summaryrefslogtreecommitdiff
path: root/loginrec.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-10-22 16:49:22 +1000
committerDamien Miller <djm@mindrot.org>2001-10-22 16:49:22 +1000
commit3a8a5cd5b075c02dac1d802765eec6c1ff5c11d6 (patch)
treea1ce6882410eb1c5fc1f568ed96500930711d456 /loginrec.c
parent13aae5ee7673a0b75369256e7ed6117f9f1b6c7d (diff)
downloadopenssh-git-3a8a5cd5b075c02dac1d802765eec6c1ff5c11d6.tar.gz
- (djm) Fix fd leak in loginrec.c (ro fd to lastlog was left open).
Report from Michal Zalewski <lcamtuf@coredump.cx>
Diffstat (limited to 'loginrec.c')
-rw-r--r--loginrec.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/loginrec.c b/loginrec.c
index 140cd3f6..8d0b3b81 100644
--- a/loginrec.c
+++ b/loginrec.c
@@ -163,7 +163,7 @@
#include "log.h"
#include "atomicio.h"
-RCSID("$Id: loginrec.c,v 1.35 2001/10/02 00:29:00 stevesk Exp $");
+RCSID("$Id: loginrec.c,v 1.36 2001/10/22 06:49:23 djm Exp $");
#ifdef HAVE_UTIL_H
# include <util.h>
@@ -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 */