]> granicus.if.org Git - postgresql/commitdiff
Fix null pointer dereference in "\c" psql command.
authorNoah Misch <noah@leadboat.com>
Thu, 9 Jul 2015 00:44:21 +0000 (20:44 -0400)
committerNoah Misch <noah@leadboat.com>
Thu, 9 Jul 2015 00:44:27 +0000 (20:44 -0400)
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).

src/bin/psql/command.c

index cd4309c46556b1270f103a6cba95a9c6aa7f2d06..f24d0a79cc54d20cca587ef30009541432f9b376 100644 (file)
@@ -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);