Skip to content

Commit a4c8f14

Browse files
committed
libpq: pass a memory allocation failure error up to PQconndefaults()
Previously user name memory allocation failures were ignored and the default user name set to NULL.
1 parent d1bdab2 commit a4c8f14

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/interfaces/libpq/fe-auth.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,16 +741,18 @@ pg_fe_getauthname(void)
741741
*/
742742
pglock_thread();
743743

744-
if (!name)
745-
{
744+
/*
745+
* We document PQconndefaults() to return NULL for a memory allocation
746+
* failure. We don't have an API to return a user name lookup failure,
747+
* so we just assume it always succeeds.
748+
*/
746749
#ifdef WIN32
747-
if (GetUserName(username, &namesize))
748-
name = username;
750+
if (GetUserName(username, &namesize))
751+
name = username;
749752
#else
750-
if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pw) == 0)
751-
name = pw->pw_name;
753+
if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pw) == 0)
754+
name = pw->pw_name;
752755
#endif
753-
}
754756

755757
authn = name ? strdup(name) : NULL;
756758

src/interfaces/libpq/fe-connect.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4482,6 +4482,13 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
44824482
if (strcmp(option->keyword, "user") == 0)
44834483
{
44844484
option->val = pg_fe_getauthname();
4485+
if (!option->val)
4486+
{
4487+
if (errorMessage)
4488+
printfPQExpBuffer(errorMessage,
4489+
libpq_gettext("out of memory\n"));
4490+
return false;
4491+
}
44854492
continue;
44864493
}
44874494
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy