...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> void open_some_file(const char *file) { FILE *f = fopen(file, "rb"); if (NULL == f) { /* Handle error */ } /* Read file */ if (fclose(f) == EOF) { /* Handle error */ } } |
Exceptions
FIO45-EX1: Accessing a filename or path multiple times is permitted if it is requested specifically by a user. A program that accepts commands from a user to read or write to a specific filename or path does not violate this standard. Example programs would include file managers or text editorsTOCTOU race conditions require that the vulnerable process is more privileged than the attacker; otherwise there is nothing to be gained to a succesfull attack.
FIO45-EX2: Accessing a path multiple times is permitted if the path can not be modified by an attacker. This could occur, for example, if the path refers to a secure directory (for more information, see FIO15-C. Ensure that file operations are performed in a secure directory).
FIO45-EX3: Repeatedly opening and closing a file in append mode (in order to add data) is permitted as an exception to this rule. Many servers will open a log file for appending, write log messages, and immediately close the file. The server does not care if this log file changes, and many systems archive old log files and create a new empty log file periodically.FIO45-EX4: Accessing a path multiple times is permitted if the program is able to verify that every operation indeed operates on the same file.
...