BUG #4837: initdb segv's if getpwuid fails

Started by Dave Vitekalmost 17 years ago2 messagesbugs
Jump to latest
#1Dave Vitek
dvitek@grammatech.com

The following bug has been logged online:

Bug reference: 4837
Logged by: David Vitek
Email address: dvitek@grammatech.com
PostgreSQL version: 8.3
Operating system: Non-Windows
Description: initdb segv's if getpwuid fails
Details:

We've seen this happen in a deployment, and we are currently assuming the
user has some configuration problem. Here's a patch (ignore the
revisions):

Index: src/bin/initdb/initdb.c
===================================================================
--- src/bin/initdb/initdb.c     (revision 48282)
+++ src/bin/initdb/initdb.c     (working copy)
@@ -660,10 +660,18 @@
 #ifndef WIN32

struct passwd *pw;
+ uid_t uid = geteuid();

-       pw = getpwuid(geteuid());
+        errno = 0; /* getpwuid may not alter errno on failure */
+       pw = getpwuid(uid);
+        if( !pw )
+        {
+            fprintf(stderr, _("%s: getpwuid failed: %s\n"),
+                    progname, strerror(errno));
+            exit(1);
+        }
-       if (geteuid() == 0)                     /* 0 is root's uid */
+       if (uid == 0)                   /* 0 is root's uid */
        {
                fprintf(stderr,
                                _("%s: cannot be run as root\n"
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dave Vitek (#1)
Re: BUG #4837: initdb segv's if getpwuid fails

"David Vitek" <dvitek@grammatech.com> writes:

Description: initdb segv's if getpwuid fails

This was reported previously, and there is already a patch in place for
PG 8.4. But thanks for the report!

regards, tom lane