Skip to content

Commit fb990ce

Browse files
committed
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).
1 parent 080c4da commit fb990ce

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/bin/psql/command.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
16411641
* positional syntax.
16421642
*/
16431643
keep_password =
1644-
((strcmp(user, PQuser(o_conn)) == 0) &&
1644+
(o_conn &&
1645+
(strcmp(user, PQuser(o_conn)) == 0) &&
16451646
(!host || strcmp(host, PQhost(o_conn)) == 0) &&
16461647
(strcmp(port, PQport(o_conn)) == 0) &&
16471648
!has_connection_string);
@@ -1768,7 +1769,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
17681769
/* Tell the user about the new connection */
17691770
if (!pset.quiet)
17701771
{
1771-
if (param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
1772+
if (!o_conn ||
1773+
param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
17721774
param_is_newly_set(PQport(o_conn), PQport(pset.db)))
17731775
{
17741776
char *host = PQhost(pset.db);

0 commit comments

Comments
 (0)