summaryrefslogtreecommitdiffstats
path: root/phantasia
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2009-05-26 00:27:23 +0000
committerdholland <dholland@NetBSD.org>2009-05-26 00:27:23 +0000
commit8053a125d99718a8c77d9ce35bc4d0c80119ec8f (patch)
treef8b43637a720680b73107fb2e2ad843be4a2daea /phantasia
parenta623d7c672cb99301a9e7f294ee836f9795f5af5 (diff)
downloadbsdgames-darwin-8053a125d99718a8c77d9ce35bc4d0c80119ec8f.tar.gz
bsdgames-darwin-8053a125d99718a8c77d9ce35bc4d0c80119ec8f.tar.zst
bsdgames-darwin-8053a125d99718a8c77d9ce35bc4d0c80119ec8f.zip
Avoid SIGSEGV on users not in password file. From pjanzen of OpenBSD.
Diffstat (limited to 'phantasia')
-rw-r--r--phantasia/main.c13
1 files changed, 10 insertions, 3 deletions
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 <sys/stat.h>
#include <sys/types.h>
+#include <err.h>
#include <pwd.h>
/*
@@ -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)