diff options
author | Magnus Hagander <magnus@hagander.net> | 2009-03-31 18:58:26 +0000 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2009-03-31 18:58:26 +0000 |
commit | 7daa32daa9b28668ac12dac2d779df2648448cdc (patch) | |
tree | f2e52a6d13f45fc08553ed92f394c9e6915ac8f8 | |
parent | 199d8bb60a12def69ad54c11ea26325a48c9a2ad (diff) | |
download | postgresql-7daa32daa9b28668ac12dac2d779df2648448cdc.tar.gz postgresql-7daa32daa9b28668ac12dac2d779df2648448cdc.zip |
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.
-rw-r--r-- | src/bin/initdb/initdb.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 3469fa506cf..b0db486176a 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -42,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.99.2.3 2006/05/27 18:07:22 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.99.2.4 2009/03/31 18:58:26 mha Exp $ * *------------------------------------------------------------------------- */ @@ -642,6 +642,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 @@ -653,7 +660,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); |