From: Magnus Hagander Date: Tue, 31 Mar 2009 18:58:20 +0000 (+0000) Subject: Don't crash initdb when we fail to get the current username. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=4ec08898eed16eae1a910f335ef2c7dc9473adbc;p=users%2Fbernd%2Fpostgres.git 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. --- diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index f1eb2faa81..f3c9e61f0e 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -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);