postgres.git / summary / log / commit / refs

commit    9a427cde74718a02abd9c699e1d2d4ee223584c7
Author:   Magnus Hagander <magnus@hagander.net>
Date:     Tue Mar 31 18:58:38 2009 +0000
First released in: 8.4.0, 8.0.22, 8.1.18, 8.2.14, 8.3.8

    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.


src/bin/initdb/initdb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index c3b7ee1b3da..e3b00cec7df 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.152.2.4 2008/10/30 08:51:13 petere Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.152.2.5 2009/03/31 18:58:38 mha Exp $ * *------------------------------------------------------------------------- */ @@ -673,6 +673,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 @@ -684,7 +691,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); [parent: 6bd988355758]