summaryrefslogtreecommitdiff
path: root/src/bin/psql/command.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2015-07-08 20:44:21 -0400
committerNoah Misch <noah@leadboat.com>2015-07-08 20:44:26 -0400
commit49008d64507858678becf59f7e7caa75afb04cf2 (patch)
treea8ef594aace8c388dbc67b0e2b27ba0d9f748431 /src/bin/psql/command.c
parentdca992d8b099ab71b14cd4aa09f31506e3903224 (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/psql/command.c')
-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 89bda00d1ae..b6558431225 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1591,7 +1591,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);
@@ -1718,7 +1719,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);