Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Ensure that slots are zeroed before use
authorDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 26 Oct 2021 08:40:08 +0000 (10:40 +0200)
committerDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 26 Oct 2021 08:40:08 +0000 (10:40 +0200)
The previous coding relied on the memory for the slots being zeroed
elsewhere, which while it was true in this case is not an contract
which is guaranteed to hold.  Explicitly clear the tts_isnull array
to ensure that the slots are filled from a known state.

Backpatch to v14 where the catalog multi-inserts were introduced.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAJ7c6TP0AowkUgNL6zcAK-s5HYsVHVBRWfu69FRubPpfwZGM9A@mail.gmail.com
Backpatch-through: 14

src/backend/catalog/heap.c
src/backend/catalog/pg_shdepend.c

index 09370a8a5a0a495ebf228248028bc5fbe6d50b0b..cc08af647e1c075add925f1ebdc4090a24d6c201 100644 (file)
@@ -766,6 +766,9 @@ InsertPgAttributeTuples(Relation pg_attribute_rel,
 
        ExecClearTuple(slot[slotCount]);
 
+       memset(slot[slotCount]->tts_isnull, false,
+              slot[slotCount]->tts_tupleDescriptor->natts * sizeof(bool));
+
        if (new_rel_oid != InvalidOid)
            slot[slotCount]->tts_values[Anum_pg_attribute_attrelid - 1] = ObjectIdGetDatum(new_rel_oid);
        else
index f8c1fd1806f55d5b2077265e0471eb775d95798e..d0c96b6de1db88c67fa633858869abfab9373e55 100644 (file)
@@ -907,6 +907,9 @@ copyTemplateDependencies(Oid templateDbId, Oid newDbId)
 
        ExecClearTuple(slot[slot_stored_count]);
 
+       memset(slot[slot_stored_count]->tts_isnull, false,
+              slot[slot_stored_count]->tts_tupleDescriptor->natts * sizeof(bool));
+
        shdep = (Form_pg_shdepend) GETSTRUCT(tup);
 
        slot[slot_stored_count]->tts_values[Anum_pg_shdepend_dbid - 1] = ObjectIdGetDatum(newDbId);