56e51f
From 3fc3a07a03ef74fde99db40ce9ef43ccab336205 Mon Sep 17 00:00:00 2001
56e51f
From: MertsA <andrewmerts@gmail.com>
56e51f
Date: Fri, 23 Jul 2021 03:36:05 -0700
56e51f
Subject: [PATCH] Rewind utmp file pointer after searching for entry
56e51f
56e51f
getutline() advances the file pointer until it matches or reaches EOF. pututline() starts from the current position in utmp. This rewinds the file pointer to the beginning to avoid allocating additional spurious utmp entries.
56e51f
---
56e51f
 src/utmp.c | 1 +
56e51f
 1 file changed, 1 insertion(+)
56e51f
56e51f
diff --git a/src/utmp.c b/src/utmp.c
56e51f
index 544a37519..952bf3043 100644
56e51f
--- a/src/utmp.c
56e51f
+++ b/src/utmp.c
56e51f
@@ -210,6 +210,7 @@ utmp_login(const char *from_line, const char *to_line, int ttyfd,
56e51f
 	memset(&utbuf, 0, sizeof(utbuf));
56e51f
 	strncpy(utbuf.ut_line, from_line, sizeof(utbuf.ut_line));
56e51f
 	ut_old = sudo_getutline(&utbuf);
56e51f
+	sudo_setutent();
56e51f
     }
56e51f
     utmp_fill(to_line, user, ut_old, &utbuf);
56e51f
     if (sudo_pututline(&utbuf) != NULL)