postgres.git / summary / log / commit / refs

commit    fb990ce6c7d99d329843e5d70d4cdaf8d0825b38
Author:   Noah Misch <noah@leadboat.com>
Date:     Thu Jul 09 00:44:21 2015 +0000
First released in: 9.6.0, 9.0.23, 9.1.19, 9.2.14, 9.3.10, 9.4.5, 9.5.0

    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).


src/bin/psql/command.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 38253fa0988..467e34b1ffc 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1641,7 +1641,8 @@ do_connect(char *dbname, char *user, char *host, char *port) * positional 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); @@ -1768,7 +1769,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); [parent: 080c4dab3d95]