From 2930c05634bcb7491bc443a493405e927ed08443 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Wed, 20 Feb 2013 16:22:47 +0200
Subject: [PATCH] Don't pass NULL to fprintf, if a bogus connection string is
 given to pg_dump.

Back-patch to all supported branches.
---
 src/bin/pg_dump/pg_backup_db.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 21c203e8e7b..4c4f24f7d5a 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -300,7 +300,8 @@ ConnectDatabase(Archive *AHX,
 	/* check to see that the backend connection was successfully made */
 	if (PQstatus(AH->connection) == CONNECTION_BAD)
 		exit_horribly(modulename, "connection to database \"%s\" failed: %s",
-					  PQdb(AH->connection), PQerrorMessage(AH->connection));
+					  PQdb(AH->connection) ? PQdb(AH->connection) : "",
+					  PQerrorMessage(AH->connection));
 
 	/* check for version mismatch */
 	_check_database_version(AH);
-- 
GitLab