From ce49121d81b7f2f62e8ba334029d6403dc947fd5 Mon Sep 17 00:00:00 2001 From: djm Date: Mon, 22 Oct 2001 06:49:22 +0000 Subject: [PATCH] - (djm) Fix fd leak in loginrec.c (ro fd to lastlog was left open). Report from Michal Zalewski --- ChangeLog | 4 ++++ loginrec.c | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29d9b30a..066e0afd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +20011022 + - (djm) Fix fd leak in loginrec.c (ro fd to lastlog was left open). + Report from Michal Zalewski + 20011021 - (tim) [configure.in] Clean up library testing. Add optional PATH to --with-pcre, --with-zlib, and --with-tcp-wrappers. Based on diff --git a/loginrec.c b/loginrec.c index e1e9ce89..5e9f96fb 100644 --- a/loginrec.c +++ b/loginrec.c @@ -1487,17 +1487,20 @@ lastlog_get_entry(struct logininfo *li) struct lastlog last; int fd; - if (lastlog_openseek(li, &fd, O_RDONLY)) { - if (atomicio(read, fd, &last, sizeof(last)) != sizeof(last)) { - log("lastlog_get_entry: Error reading from %s: %s", - LASTLOG_FILE, strerror(errno)); - return 0; - } else { - lastlog_populate_entry(li, &last); - return 1; - } - } else { + if (!lastlog_openseek(li, &fd, O_RDONLY)) + return 0; + + if (atomicio(read, fd, &last, sizeof(last)) != sizeof(last)) { + close(fd); + log("lastlog_get_entry: Error reading from %s: %s", + LASTLOG_FILE, strerror(errno)); return 0; } + + close(fd); + + lastlog_populate_entry(li, &last); + + return 1; } #endif /* USE_LASTLOG */ -- 2.45.2