diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-09-08 19:14:40 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-09-08 19:14:40 -0400 |
commit | 2e62fa62d6745ba3bcb0a517d002aff1f3cdefb7 (patch) | |
tree | 89e611fd20a4e87b7002cde29544a0bc3285a368 /src | |
parent | d8df7ac5c04cd17bf13bd3123dcfcaf8007c6280 (diff) | |
download | postgresql-2e62fa62d6745ba3bcb0a517d002aff1f3cdefb7.tar.gz postgresql-2e62fa62d6745ba3bcb0a517d002aff1f3cdefb7.zip |
Avoid core dump after getpwuid_r failure.
Looking up a nonexistent user ID would lead to a null pointer
dereference. That's unlikely to happen here, but perhaps
not impossible.
Thinko in commit 4d5111b3f, noticed by Coverity.
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/libpq/fe-auth.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 4904d38ce1c..20d3427e943 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -1205,7 +1205,7 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage) DWORD namesize = sizeof(username); #else struct passwd pwbuf; - struct passwd *pw; + struct passwd *pw = NULL; char buf[1024]; int rc; #endif @@ -1230,7 +1230,8 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage) if (errorMessage) libpq_append_error(errorMessage, "local user with ID %ld does not exist", (long) user_id); } - name = pw->pw_name; + else + name = pw->pw_name; #endif if (name) |