diff options
author | Sami Kerola | 2015-10-31 20:21:13 +0100 |
---|---|---|
committer | Karel Zak | 2015-11-09 09:56:14 +0100 |
commit | a64e268224a142210e135c2b409c4f65743e476a (patch) | |
tree | df13ca80614b23230d5d43f37c0aab1acce808ec /login-utils/login.c | |
parent | logger: shadow declaration (diff) | |
download | kernel-qcow2-util-linux-a64e268224a142210e135c2b409c4f65743e476a.tar.gz kernel-qcow2-util-linux-a64e268224a142210e135c2b409c4f65743e476a.tar.xz kernel-qcow2-util-linux-a64e268224a142210e135c2b409c4f65743e476a.zip |
login: fix stat(2) race
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/login.c')
-rw-r--r-- | login-utils/login.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/login-utils/login.c b/login-utils/login.c index 0e45de7ac..b70846771 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); } |