Commit 84a059ab authored by Magnus Hagander's avatar Magnus Hagander

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.
parent df13324f
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD. * Portions taken from FreeBSD.
* *
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.168 2009/02/25 13:03:06 petere Exp $ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.169 2009/03/31 18:58:16 mha Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -670,6 +670,13 @@ get_id(void) ...@@ -670,6 +670,13 @@ get_id(void)
progname); progname);
exit(1); 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 */ #else /* the windows code */
struct passwd_win32 struct passwd_win32
...@@ -681,7 +688,12 @@ get_id(void) ...@@ -681,7 +688,12 @@ get_id(void)
DWORD pwname_size = sizeof(pass_win32.pw_name) - 1; DWORD pwname_size = sizeof(pass_win32.pw_name) - 1;
pw->pw_uid = 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 #endif
return xstrdup(pw->pw_name); return xstrdup(pw->pw_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment