diff options
author | Bruce Momjian <bruce@momjian.us> | 2013-12-03 11:11:56 -0500 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2013-12-03 11:12:25 -0500 |
commit | 9e0a97f1c8316e36fa4a8626e0a60792b0fb0c2e (patch) | |
tree | 659c15fa695ca0fc7ccbedde530ea54ead06e2f2 /src | |
parent | 95e3d50539afcdcd4b75b4ac5baa9f8fc05324d9 (diff) | |
download | postgresql-9e0a97f1c8316e36fa4a8626e0a60792b0fb0c2e.tar.gz |
libpq: change PQconndefaults() to ignore invalid service files
Previously missing or invalid service files returned NULL. Also fix
pg_upgrade to report "out of memory" for a null return from
PQconndefaults().
Patch by Steve Singer, rewritten by me
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/libpq/fe-auth.c | 2 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-auth.h | 2 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 27 |
3 files changed, 18 insertions, 13 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 975f7958d1..979714055e 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -982,7 +982,7 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn) * if there is an error, return NULL with an error message in errorMessage */ char * -pg_fe_getauthname(PQExpBuffer errorMessage) +pg_fe_getauthname(void) { const char *name = NULL; char *authn; diff --git a/src/interfaces/libpq/fe-auth.h b/src/interfaces/libpq/fe-auth.h index bfddc682b1..25440b06bd 100644 --- a/src/interfaces/libpq/fe-auth.h +++ b/src/interfaces/libpq/fe-auth.h @@ -19,6 +19,6 @@ extern int pg_fe_sendauth(AuthRequest areq, PGconn *conn); -extern char *pg_fe_getauthname(PQExpBuffer errorMessage); +extern char *pg_fe_getauthname(void); #endif /* FE_AUTH_H */ diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 8dd1a5960f..7ab4a9a362 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -875,7 +875,8 @@ PQconndefaults(void) connOptions = conninfo_init(&errorBuf); if (connOptions != NULL) { - if (!conninfo_add_defaults(connOptions, &errorBuf)) + /* pass NULL errorBuf to ignore errors */ + if (!conninfo_add_defaults(connOptions, NULL)) { PQconninfoFree(connOptions); connOptions = NULL; @@ -4412,9 +4413,10 @@ conninfo_array_parse(const char *const * keywords, const char *const * values, * * Defaults are obtained from a service file, environment variables, etc. * - * Returns TRUE if successful, otherwise FALSE; errorMessage is filled in - * upon failure. Note that failure to locate a default value is not an - * error condition here --- we just leave the option's value as NULL. + * Returns TRUE if successful, otherwise FALSE; errorMessage, if supplied, + * is filled in upon failure. Note that failure to locate a default value + * is not an error condition here --- we just leave the option's value as + * NULL. */ static bool conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage) @@ -4424,9 +4426,10 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage) /* * If there's a service spec, use it to obtain any not-explicitly-given - * parameters. + * parameters. Ignore error if no error message buffer is passed + * because there is no way to pass back the failure message. */ - if (parseServiceInfo(options, errorMessage) != 0) + if (parseServiceInfo(options, errorMessage) != 0 && errorMessage) return false; /* @@ -4448,8 +4451,9 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage) option->val = strdup(tmp); if (!option->val) { - printfPQExpBuffer(errorMessage, - libpq_gettext("out of memory\n")); + if (errorMessage) + printfPQExpBuffer(errorMessage, + libpq_gettext("out of memory\n")); return false; } continue; @@ -4465,8 +4469,9 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage) option->val = strdup(option->compiled); if (!option->val) { - printfPQExpBuffer(errorMessage, - libpq_gettext("out of memory\n")); + if (errorMessage) + printfPQExpBuffer(errorMessage, + libpq_gettext("out of memory\n")); return false; } continue; @@ -4477,7 +4482,7 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage) */ if (strcmp(option->keyword, "user") == 0) { - option->val = pg_fe_getauthname(errorMessage); + option->val = pg_fe_getauthname(); continue; } } |