From: Sami Kerola Date: Sat, 31 Oct 2015 19:21:13 +0000 (+0000) Subject: login: fix stat(2) race X-Git-Tag: v2.28-rc1~285 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a64e268224a142210e135c2b409c4f65743e476a;p=thirdparty%2Futil-linux.git login: fix stat(2) race Signed-off-by: Sami Kerola --- diff --git a/login-utils/login.c b/login-utils/login.c index 0e45de7ac3..b70846771c 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -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); }