Skip to content

Commit 9880fea

Browse files
committed
Allow "dbname" from connection string to be overridden in PQconnectDBParams
If the "dbname" attribute in PQconnectDBParams contained a connection string or URI (and expand_dbname = TRUE), the database name from the connection string could not be overridden by a subsequent "dbname" keyword in the array. That was not intentional; all other options can be overridden. Furthermore, any subsequent "dbname" caused the connection string from the first dbname value to be processed again, overriding any values for the same options that were given between the connection string and the second dbname option. In the passing, clarify in the docs that only the first dbname option in the array is parsed as a connection string. Alex Shulgin. Backpatch to all supported versions.
1 parent 1f35170 commit 9880fea

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4221,9 +4221,9 @@ conninfo_array_parse(const char **keywords, const char **values,
42214221
}
42224222

42234223
/*
4224-
* If we are on the dbname parameter, and we have a parsed
4225-
* conninfo string, copy those parameters across, overriding any
4226-
* existing previous settings
4224+
* If we are on the first dbname parameter, and we have a parsed
4225+
* connection string, copy those parameters across, overriding any
4226+
* existing previous settings.
42274227
*/
42284228
if (strcmp(pname, "dbname") == 0 && str_options)
42294229
{
@@ -4255,6 +4255,12 @@ conninfo_array_parse(const char **keywords, const char **values,
42554255
}
42564256
}
42574257
}
4258+
/*
4259+
* Forget the parsed connection string, so that any subsequent
4260+
* dbname parameters will not be expanded.
4261+
*/
4262+
PQconninfoFree(str_options);
4263+
str_options = NULL;
42584264
}
42594265
else
42604266
{

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