Don't crash initdb when we fail to get the current username.
authorMagnus Hagander <[email protected]>
Tue, 31 Mar 2009 18:58:26 +0000 (18:58 +0000)
committerMagnus Hagander <[email protected]>
Tue, 31 Mar 2009 18:58:26 +0000 (18:58 +0000)
Give an error message and exit instead, like we do elsewhere...

Per report from Wez Furlong and Robert Treat.

src/bin/initdb/initdb.c

index 3ce8d22a0632fb8407c2bb94f88ce22eab82a74d..830d3c1627640be8ca30f37f6638611e64818f80 100644 (file)
@@ -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);