summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2009-03-31 18:58:16 +0000
committerMagnus Hagander2009-03-31 18:58:16 +0000
commit6d81ebf8a327fac5af8b79b754edd4bdf53553f1 (patch)
tree367d5a2c9b659191ec9f363d7090f9e8bc20f81c
parent722c1dd97274598ddfcda3b770f5325297618c3a (diff)
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.
-rw-r--r--src/bin/initdb/initdb.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index de18bc567c..804226c261 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -670,6 +670,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
@@ -681,7 +688,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);