summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-auth.c
diff options
context:
space:
mode:
authorBruce Momjian2014-03-20 15:48:31 +0000
committerBruce Momjian2014-03-20 15:48:31 +0000
commita4c8f14364c27508233f8a31ac4b10a4c90235a9 (patch)
tree2eb0dad6c952ec5331986e836f5cee38356328b0 /src/interfaces/libpq/fe-auth.c
parentd1bdab2fa39f9a29fc806e1f2b6b5428b88d7cc5 (diff)
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.
Diffstat (limited to 'src/interfaces/libpq/fe-auth.c')
-rw-r--r--src/interfaces/libpq/fe-auth.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index e10c9709108..5ddd17d5df7 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -741,16 +741,18 @@ pg_fe_getauthname(void)
*/
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
- if (GetUserName(username, &namesize))
- name = username;
+ if (GetUserName(username, &namesize))
+ name = username;
#else
- if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pw) == 0)
- name = pw->pw_name;
+ if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pw) == 0)
+ name = pw->pw_name;
#endif
- }
authn = name ? strdup(name) : NULL;