From: Noah Misch Date: Thu, 9 Jul 2015 00:44:21 +0000 (-0400) Subject: Fix null pointer dereference in "\c" psql command. X-Git-Tag: REL9_0_23~82 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6087bf1a198e42b811637101580af51a55fac505;p=thirdparty%2Fpostgresql.git 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). --- diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index cd4309c4655..f24d0a79cc5 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1260,7 +1260,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);