~/ learn/ comp-400/ cards/ The CWE/SANS Top 25, input validation, and safe coding
1 of 10

The check-then-create race

The check-then-create race

Answer

/* RACE: another process can create the file in this gap */ if (access(LOCKPATH, F_OK) != 0) { fd = open(LOCKPATH, O_WRONLY | O_CREAT, 0600); write(fd, pidbuf, n); }

Two processes can both reach the `open` having both seen no lockfile, and both believe they hold the lock. The window is small, and an attacker who can trigger the code repeatedly does not care how small.

Stallings & Brown 5e ch11 §11.1–11.6

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/6675bc49-b05d-40ef-b086-e491f5e5dd66/flashcard utf-8 LF