diff options
author | Karel Zak | 2017-05-17 12:59:33 +0200 |
---|---|---|
committer | Karel Zak | 2017-05-17 12:59:33 +0200 |
commit | dd732fa25160d2855acb9d4ce46be77d984a73b4 (patch) | |
tree | 9a402318472ec2a6b872956a865dc54400e5368a /login-utils/nologin.c | |
parent | libsmartcols: check scols_table_set_default_symbols() return code [coverity s... (diff) | |
download | kernel-qcow2-util-linux-dd732fa25160d2855acb9d4ce46be77d984a73b4.tar.gz kernel-qcow2-util-linux-dd732fa25160d2855acb9d4ce46be77d984a73b4.tar.xz kernel-qcow2-util-linux-dd732fa25160d2855acb9d4ce46be77d984a73b4.zip |
nologin: don't call fstat() after failed open() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/nologin.c')
-rw-r--r-- | login-utils/nologin.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/login-utils/nologin.c b/login-utils/nologin.c index 2e897cc72..e950d2a3f 100644 --- a/login-utils/nologin.c +++ b/login-utils/nologin.c @@ -38,7 +38,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) int main(int argc, char *argv[]) { - int c, fd; + int c, fd = -1; struct stat st; static const struct option longopts[] = { { "help", 0, NULL, 'h' }, @@ -64,16 +64,26 @@ int main(int argc, char *argv[]) } fd = open(_PATH_NOLOGIN_TXT, O_RDONLY); + if (fd < 0) + goto dflt; + c = fstat(fd, &st); - if (fd >= 0 && !c && S_ISREG(st.st_mode)) { + if (c < 0 || !S_ISREG(st.st_mode)) + goto dflt; + else { char buf[BUFSIZ]; ssize_t rd; while ((rd = read(fd, buf, sizeof(buf))) > 0) ignore_result( write(STDOUT_FILENO, buf, rd) ); + close(fd); - } else - fprintf(stdout, _("This account is currently not available.\n")); + return EXIT_FAILURE; + } +dflt: + if (fd >= 0) + close(fd); + fprintf(stdout, _("This account is currently not available.\n")); return EXIT_FAILURE; } |