From caf4802b0a64622092f673bac11964229f262273 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 16 Jun 2020 17:47:20 +0100 Subject: [PATCH] setup_utmp: add error check in case getpwuid fails. Spotted by Coverity: if there is no password file entry associated with our numeric uid, we'll press on anyway and dereference NULL. --- unix/uxpty.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unix/uxpty.c b/unix/uxpty.c index 721074fc..d7b8e177 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -206,6 +206,8 @@ static void setup_utmp(char *ttyname, char *location) struct timeval tv; pw = getpwuid(getuid()); + if (!pw) + return; /* can't stamp utmp if we don't have a username */ memset(&utmp_entry, 0, sizeof(utmp_entry)); utmp_entry.ut_type = USER_PROCESS; utmp_entry.ut_pid = getpid();