Bug 110 - bogus error messages in lastlog_get_entry()
Summary: bogus error messages in lastlog_get_entry()
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: -current
Hardware: ix86 Linux
: P2 minor
Assignee: OpenSSH Bugzilla mailing list
URL:
Keywords:
: 492 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-02-13 09:32 AEDT by Pavel Kankovsky
Modified: 2004-04-14 12:24 AEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Kankovsky 2002-02-13 09:32:25 AEDT
When sshd tries to read beyond the end of lastlog, e.g. when logging to a
high-uid user that has never logged in yet, atomicio() returns 0 and
lastlog_get_entry() generates a bogus error message for errno==0 (e.g.
"lastlog_get_entry: Error reading from /var/log/lastlog: Success"). The
following patch prevents it. Also, I made an attempt to report partial reads in
a proper way.

diff -urN openssh-3.0.2p1.old/loginrec.c openssh-3.0.2p1/loginrec.c
--- openssh-3.0.2p1.old/loginrec.c	Tue Oct 30 03:50:40 2001
+++ openssh-3.0.2p1/loginrec.c	Tue Feb 12 23:16:43 2002
@@ -1486,15 +1486,23 @@
 lastlog_get_entry(struct logininfo *li)
 {
 	struct lastlog last;
-	int fd;
+	int fd, r;
 
 	if (!lastlog_openseek(li, &fd, O_RDONLY))
 		return 0;
 
-	if (atomicio(read, fd, &last, sizeof(last)) != sizeof(last)) {
+	r = atomicio(read, fd, &last, sizeof(last));
+	if (r == 0) {
+		/* no recorded login */
+		memset(&last, '\0', sizeof(last));
+	} else if (r != sizeof(last)) {
 		close(fd);
-		log("lastlog_get_entry: Error reading from %s: %s",
-		    LASTLOG_FILE, strerror(errno));
+		if (r == -1)
+			log("lastlog_get_entry: Error reading from %s: %s",
+			    LASTLOG_FILE, strerror(errno));
+		else
+			log("lastlog_get_entry: Error reading from %s: read %d bytes, expected %d",
+			    LASTLOG_FILE, r, sizeof(last));
 		return 0;
 	}
Comment 1 Damien Miller 2003-01-07 16:47:09 AEDT
Similar fix applied - thanks.
Comment 2 Damien Miller 2003-02-12 11:58:45 AEDT
*** Bug 492 has been marked as a duplicate of this bug. ***
Comment 3 Damien Miller 2004-04-14 12:24:17 AEST
Mass change of RESOLVED bugs to CLOSED