]> granicus.if.org Git - postgresql/commitdiff
In initdb, defend against assignment of NULL values to not-null columns.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Jun 2017 14:54:39 +0000 (10:54 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 13 Jun 2017 14:54:43 +0000 (10:54 -0400)
Previously, you could write _null_ in a BKI DATA line for a column that's
supposed to be NOT NULL and initdb would let it pass, probably breaking
subsequent accesses to the row.  No doubt the original coding overlooked
this simple sanity check because in the beginning we didn't have any way
to mark catalog columns NOT NULL at initdb time.

src/backend/bootstrap/bootstrap.c

index 4c28b2b821a767ef7a262312b6102bc844244f30..d2708cb33e9b5c35351eafefef0b2f3ca6bc24a2 100644 (file)
@@ -843,6 +843,11 @@ InsertOneNull(int i)
 {
        elog(DEBUG4, "inserting column %d NULL", i);
        Assert(i >= 0 && i < MAXATTR);
+       if (boot_reldesc->rd_att->attrs[i]->attnotnull)
+               elog(ERROR,
+               "NULL value specified for not-null column \"%s\" of relation \"%s\"",
+                        NameStr(boot_reldesc->rd_att->attrs[i]->attname),
+                        RelationGetRelationName(boot_reldesc));
        values[i] = PointerGetDatum(NULL);
        Nulls[i] = true;
 }