Skip to content

Commit ed46d0d

Browse files
committed
Repair unsafe/unportable snprintf usage in pg_restore.
warn_or_exit_horribly() was blithely passing a potentially-NULL string pointer to a %s format specifier. That works (at least to the extent of not crashing) on some platforms, but not all, and since we switched to our own snprintf.c it doesn't work for us anywhere. Of the three string fields being handled this way here, I think that only "owner" is supposed to be nullable ... but considering that this is error-reporting code, it has very little business assuming anything, so put in defenses for all three. Per a crash observed on buildfarm member crake and then reproduced here. Because of the portability aspect, back-patch to all supported versions.
1 parent 37f3a77 commit ed46d0d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,8 +1676,11 @@ warn_or_exit_horribly(ArchiveHandle *AH,
16761676
{
16771677
write_msg(modulename, "Error from TOC entry %d; %u %u %s %s %s\n",
16781678
AH->currentTE->dumpId,
1679-
AH->currentTE->catalogId.tableoid, AH->currentTE->catalogId.oid,
1680-
AH->currentTE->desc, AH->currentTE->tag, AH->currentTE->owner);
1679+
AH->currentTE->catalogId.tableoid,
1680+
AH->currentTE->catalogId.oid,
1681+
AH->currentTE->desc ? AH->currentTE->desc : "(no desc)",
1682+
AH->currentTE->tag ? AH->currentTE->tag : "(no tag)",
1683+
AH->currentTE->owner ? AH->currentTE->owner : "(no owner)");
16811684
}
16821685
AH->lastErrorStage = AH->stage;
16831686
AH->lastErrorTE = AH->currentTE;

0 commit comments

Comments
 (0)