From 9350a4ce202b9f37905fdb3409078bd1a56f17bd Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Tue, 31 Mar 2009 18:58:20 +0000 Subject: [PATCH] Don't crash initdb when we fail to get the current username. Give an error message and exit instead, like we do elsewhere... Per report from Wez Furlong and Robert Treat. --- src/bin/initdb/initdb.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index d44e3cdbe53..9a42bcea078 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -39,7 +39,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.73.4.4 2006/05/21 19:57:39 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.73.4.5 2009/03/31 18:58:20 mha Exp $ * *------------------------------------------------------------------------- */ @@ -639,7 +639,13 @@ get_id(void) exit(1); } #endif - + if (!pw) + { + fprintf(stderr, + _("%s: could not obtain information about current user: %s\n"), + progname, strerror(errno)); + exit(1); + } #else /* the windows code */ struct passwd_win32 @@ -651,7 +657,12 @@ get_id(void) DWORD pwname_size = sizeof(pass_win32.pw_name) - 1; pw->pw_uid = 1; - GetUserName(pw->pw_name, &pwname_size); + if (!GetUserName(pw->pw_name, &pwname_size)) + { + fprintf(stderr, _("%s: could not get current user name: %s\n"), + progname, strerror(errno)); + exit(1); + } #endif return xstrdup(pw->pw_name); -- 2.39.5