From b349762fdeb7193b55fd1ae44a2e79903f13b14a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 26 Sep 2026 12:55:40 -0400 Subject: [PATCH] Don't emit garbage "\[un]restrict (null)" commands in pg_dump. _reconnectToDB() failed to consider the possibility that it could be called without any restrict_key set. This is reachable while generating the "restore.sql" file in tar dump mode, which nobody noticed because that file is mostly unused (and nothing really bad happens anyway unless you specified --inserts mode). But I wonder if there are other code paths that reach the issue. Bug: #19718 Reported-by: Pavel Kopylov Author: Pavel Kopylov Reviewed-by: Tom Lane Discussion: https://postgr.es/m/19718-7e945d0ff9b5a589@postgresql.org Backpatch-through: 14 --- src/bin/pg_dump/pg_backup_archiver.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 29a41ca8ef5..bb34bdb8b79 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -3306,14 +3306,16 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname) * Anything added between this line and the following \restrict must * be careful to avoid any possible meta-command injection vectors. */ - ahprintf(AH, "\\unrestrict %s\n", ropt->restrict_key); + if (ropt->restrict_key) + ahprintf(AH, "\\unrestrict %s\n", ropt->restrict_key); initPQExpBuffer(&connectbuf); appendPsqlMetaConnect(&connectbuf, dbname); ahprintf(AH, "%s", connectbuf.data); termPQExpBuffer(&connectbuf); - ahprintf(AH, "\\restrict %s\n\n", ropt->restrict_key); + if (ropt->restrict_key) + ahprintf(AH, "\\restrict %s\n\n", ropt->restrict_key); } /*