Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 84a059a

Browse files
committed
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.
1 parent df13324 commit 84a059a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/bin/initdb/initdb.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
* Portions taken from FreeBSD.
4444
*
45-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.168 2009/02/25 13:03:06 petere Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.169 2009/03/31 18:58:16 mha Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -670,6 +670,13 @@ get_id(void)
670670
progname);
671671
exit(1);
672672
}
673+
if (!pw)
674+
{
675+
fprintf(stderr,
676+
_("%s: could not obtain information about current user: %s\n"),
677+
progname, strerror(errno));
678+
exit(1);
679+
}
673680
#else /* the windows code */
674681

675682
struct passwd_win32
@@ -681,7 +688,12 @@ get_id(void)
681688
DWORD pwname_size = sizeof(pass_win32.pw_name) - 1;
682689

683690
pw->pw_uid = 1;
684-
GetUserName(pw->pw_name, &pwname_size);
691+
if (!GetUserName(pw->pw_name, &pwname_size))
692+
{
693+
fprintf(stderr, _("%s: could not get current user name: %s\n"),
694+
progname, strerror(errno));
695+
exit(1);
696+
}
685697
#endif
686698

687699
return xstrdup(pw->pw_name);

0 commit comments

Comments
 (0)