From 8053a125d99718a8c77d9ce35bc4d0c80119ec8f Mon Sep 17 00:00:00 2001 From: dholland Date: Tue, 26 May 2009 00:27:23 +0000 Subject: Avoid SIGSEGV on users not in password file. From pjanzen of OpenBSD. --- phantasia/main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'phantasia') diff --git a/phantasia/main.c b/phantasia/main.c index 8e206d58..3a0f919c 100644 --- a/phantasia/main.c +++ b/phantasia/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.19 2009/05/25 23:14:33 dholland Exp $ */ +/* $NetBSD: main.c,v 1.20 2009/05/26 00:27:23 dholland Exp $ */ /* * Phantasia 3.3.2 -- Interterminal fantasy game @@ -29,6 +29,7 @@ #include #include +#include #include /* @@ -271,6 +272,7 @@ void initialstate(void) { struct stat sb; + struct passwd *pw; Beyond = FALSE; Marsh = FALSE; @@ -283,8 +285,13 @@ initialstate(void) Echo = TRUE; /* setup login name */ - if ((Login = getlogin()) == NULL) - Login = getpwuid(getuid())->pw_name; + if ((Login = getlogin()) == NULL) { + pw = getpwuid(getuid()); + if (pw == NULL) { + errx(1, "Who are you?"); + } + Login = pw->pw_name; + } /* open some files */ if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL) -- cgit v1.2.3-56-ge451