]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp: merge file access
authorChristian Göttsche <cgzones@googlemail.com>
Mon, 11 Dec 2023 16:18:38 +0000 (17:18 +0100)
committerSerge Hallyn <serge@hallyn.com>
Thu, 14 Dec 2023 13:40:40 +0000 (07:40 -0600)
Avoid checking if the file exists before opening it.

Resolves a CodeQL report of Time-of-check time-of-use filesystem race
condition.

lib/utmp.c

index dabe8b2e81e1f239ae41b6f1d03be08ce954d162..6acd196f05c1570bceb296426f1643f60ef86078 100644 (file)
@@ -85,15 +85,13 @@ static void failtmp (const char *username, const struct utmp *failent)
         * 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;
        }