summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorNoah Misch2015-07-09 00:44:21 +0000
committerNoah Misch2015-07-09 00:44:27 +0000
commit458ccbf2b3a9a8566a405368825954cf99b8dbef (patch)
treeb69a089802623c919abf3de9984466162684b669 /src/bin
parentebe601c4daf3cdcde5156d941a6ae880ab94c7cd (diff)
Fix null pointer dereference in "\c" psql command.
The psql crash happened when no current connection existed. (The second new check is optional given today's undocumented NULL argument handling in PQhost() etc.) Back-patch to 9.0 (all supported versions).
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/psql/command.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 1f6c1914fef..b9880fcc577 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1526,7 +1526,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
* syntax.
*/
keep_password =
- ((strcmp(user, PQuser(o_conn)) == 0) &&
+ (o_conn &&
+ (strcmp(user, PQuser(o_conn)) == 0) &&
(!host || strcmp(host, PQhost(o_conn)) == 0) &&
(strcmp(port, PQport(o_conn)) == 0) &&
!has_connection_string);
@@ -1649,7 +1650,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
/* Tell the user about the new connection */
if (!pset.quiet)
{
- if (param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
+ if (!o_conn ||
+ param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
param_is_newly_set(PQport(o_conn), PQport(pset.db)))
{
char *host = PQhost(pset.db);