mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-15 08:20:16 +08:00
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.
This commit is contained in:
parent
d1bdab2fa3
commit
a4c8f14364
@ -741,16 +741,18 @@ pg_fe_getauthname(void)
|
|||||||
*/
|
*/
|
||||||
pglock_thread();
|
pglock_thread();
|
||||||
|
|
||||||
if (!name)
|
/*
|
||||||
{
|
* We document PQconndefaults() to return NULL for a memory allocation
|
||||||
|
* failure. We don't have an API to return a user name lookup failure,
|
||||||
|
* so we just assume it always succeeds.
|
||||||
|
*/
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (GetUserName(username, &namesize))
|
if (GetUserName(username, &namesize))
|
||||||
name = username;
|
name = username;
|
||||||
#else
|
#else
|
||||||
if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pw) == 0)
|
if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pw) == 0)
|
||||||
name = pw->pw_name;
|
name = pw->pw_name;
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
authn = name ? strdup(name) : NULL;
|
authn = name ? strdup(name) : NULL;
|
||||||
|
|
||||||
|
@ -4482,6 +4482,13 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
|
|||||||
if (strcmp(option->keyword, "user") == 0)
|
if (strcmp(option->keyword, "user") == 0)
|
||||||
{
|
{
|
||||||
option->val = pg_fe_getauthname();
|
option->val = pg_fe_getauthname();
|
||||||
|
if (!option->val)
|
||||||
|
{
|
||||||
|
if (errorMessage)
|
||||||
|
printfPQExpBuffer(errorMessage,
|
||||||
|
libpq_gettext("out of memory\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user