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=e797d83232802cf439b2ed893e784d3636357349;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);