1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00

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.
This commit is contained in:
Tom Lane 2024-09-08 19:14:40 -04:00
parent d8df7ac5c0
commit 2e62fa62d6

View File

@ -1205,7 +1205,7 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
DWORD namesize = sizeof(username); DWORD namesize = sizeof(username);
#else #else
struct passwd pwbuf; struct passwd pwbuf;
struct passwd *pw; struct passwd *pw = NULL;
char buf[1024]; char buf[1024];
int rc; int rc;
#endif #endif
@ -1230,7 +1230,8 @@ pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
if (errorMessage) if (errorMessage)
libpq_append_error(errorMessage, "local user with ID %ld does not exist", (long) user_id); 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 #endif
if (name) if (name)