I am using FlawFinder to find potential vulnerabilities in a piece of C code.
In the analysis, the tool reports this problem:
file.c:54: [2] (misc) fopen:
Check when opening files - can an attacker redirect it (via symlinks),
force the opening of special file type (e.g., device files), move things
around to create a race condition, control its ancestors, or change its
contents? (CWE-362).
The related piece of code is this one:
FILE *aFile = fopen("/tmp/tmpfile", "w");
Although I know that not all the problems reported are errors or vulnerabilities, I would like to understand why this happens and how I could potentially fix it. I tried searching the web, but all I found was about race condition and I don't understand why this piece of code could lead to race condition.
Moreover, is there an alternative function I could use instead of fopen
?