]> granicus.if.org Git - postgresql/commitdiff
Protect against NULL-dereference in pg_dump
authorStephen Frost <sfrost@snowman.net>
Fri, 6 Jan 2017 20:27:50 +0000 (15:27 -0500)
committerStephen Frost <sfrost@snowman.net>
Fri, 6 Jan 2017 20:27:50 +0000 (15:27 -0500)
findTableByOid() is allowed to return NULL and we should therefore be
checking for that case.  getOwnedSeqs() and dumpSequence() shouldn't
ever actually see this happen, but given odd circumstances it might and
commit f9e439b1 probably shouldn't have removed that check.

Pointed out by Coverity.  Initial patch from Michael Paquier.

Back-patch to 9.6, where that commit had removed the check.

src/bin/pg_dump/pg_dump.c

index 6b2a6c939bbd7af5cf4ed8405e4792ee4566166c..c3ca047463942b0ab3a49de336c496a2e00894ca 100644 (file)
@@ -6089,6 +6089,9 @@ getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
                        continue;                       /* not an owned sequence */
 
                owning_tab = findTableByOid(seqinfo->owning_tab);
+               if (owning_tab == NULL)
+                       exit_horribly(NULL, "failed sanity check, parent table OID %u of sequence OID %u not found\n",
+                                                 seqinfo->owning_tab, seqinfo->dobj.catId.oid);
 
                /*
                 * We need to dump the components that are being dumped for the table
@@ -16537,7 +16540,11 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
        {
                TableInfo  *owning_tab = findTableByOid(tbinfo->owning_tab);
 
-               if (owning_tab && owning_tab->dobj.dump & DUMP_COMPONENT_DEFINITION)
+               if (owning_tab == NULL)
+                       exit_horribly(NULL, "failed sanity check, parent table OID %u of sequence OID %u not found\n",
+                                                 tbinfo->owning_tab, tbinfo->dobj.catId.oid);
+
+               if (owning_tab->dobj.dump & DUMP_COMPONENT_DEFINITION)
                {
                        resetPQExpBuffer(query);
                        appendPQExpBuffer(query, "ALTER SEQUENCE %s",