]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: fix stat(2) race
authorSami Kerola <kerolasa@iki.fi>
Sat, 31 Oct 2015 19:21:13 +0000 (19:21 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 9 Nov 2015 08:56:14 +0000 (09:56 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/login.c

index 0e45de7ac3d9b5a2155e09e4b76f491eb2322083..b70846771c49db3bb0e9faec9072b84b56bf8728 100644 (file)
@@ -256,13 +256,11 @@ static void motd(void)
                struct stat st;
                int fd;
 
-               if (stat(motdfile, &st) || !st.st_size)
-                       continue;
                fd = open(motdfile, O_RDONLY, 0);
                if (fd < 0)
                        continue;
-
-               sendfile(fileno(stdout), fd, NULL, st.st_size);
+               if (!fstat(fd, &st) && st.st_size)
+                       sendfile(fileno(stdout), fd, NULL, st.st_size);
                close(fd);
        }