Skip to content

Commit 6087bf1

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 7a858f7 commit 6087bf1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/bin/psql/command.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
12601260
* syntax.
12611261
*/
12621262
keep_password =
1263-
((strcmp(user, PQuser(o_conn)) == 0) &&
1263+
(o_conn &&
1264+
(strcmp(user, PQuser(o_conn)) == 0) &&
12641265
(!host || strcmp(host, PQhost(o_conn)) == 0) &&
12651266
(strcmp(port, PQport(o_conn)) == 0) &&
12661267
!has_connection_string);

0 commit comments

Comments
 (0)