diff options
author | Magnus Hagander <magnus@hagander.net> | 2009-03-31 18:58:34 +0000 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2009-03-31 18:58:34 +0000 |
commit | b251244f856710bed9593dfcfd64d78c01f14901 (patch) | |
tree | 1a13644a8aa30855590afa8f7b57fab049737662 /src | |
parent | ac3c59cc805e30d69d1932d2b3e6a03bfea56908 (diff) | |
download | postgresql-b251244f856710bed9593dfcfd64d78c01f14901.tar.gz postgresql-b251244f856710bed9593dfcfd64d78c01f14901.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.
Diffstat (limited to 'src')
-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 55dbdf9284d..f965f0b2a5f 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.125.2.2 2008/02/29 23:31:57 adunstan Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.125.2.3 2009/03/31 18:58:34 mha Exp $ * *------------------------------------------------------------------------- */ @@ -647,6 +647,13 @@ get_id(void) progname); exit(1); } + 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 @@ -658,7 +665,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); |