Avoid checking if the file exists before opening it.
Resolves a CodeQL report of Time-of-check time-of-use filesystem race
condition.
* feature to be used.
*/
- if (access (ftmp, F_OK) != 0) {
- return;
- }
-
fd = open (ftmp, O_WRONLY | O_APPEND);
if (-1 == fd) {
- SYSLOG ((LOG_WARN,
- "Can't append failure of user %s to %s.",
- username, ftmp));
+ if (errno != ENOENT) {
+ SYSLOG ((LOG_WARN,
+ "Can't append failure of user %s to %s: %m",
+ username, ftmp));
+ }
return;
}