From: Karel Zak Date: Thu, 20 Sep 2007 22:34:30 +0000 (+0200) Subject: login: login segfaults on EOF (rh#298461) X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9256e4c2f01cc1d25cf3bcbb87ea6af037928a6;p=util-linux login: login segfaults on EOF (rh#298461) Stupid bug in audit code: $ login login: ^D login: ^D Segmentation fault Signed-off-by: Karel Zak --- diff --git a/login-utils/login.c b/login-utils/login.c index e582779e..1af87925 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -330,12 +330,12 @@ logaudit(const char *tty, const char *username, const char *hostname, audit_fd = audit_open(); if (audit_fd == -1) return; - if (!pwd) + if (!pwd && username) pwd = getpwnam(username); if (pwd) snprintf(buf, sizeof(buf), "uid=%d", pwd->pw_uid); else - snprintf(buf, sizeof(buf), "acct=%s", username); + snprintf(buf, sizeof(buf), "acct=%s", username ? username : "(unknown)"); audit_log_user_message(audit_fd, AUDIT_USER_LOGIN, buf, hostname, NULL, tty, status);