diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/common/tupdesc.c | 8 | ||||
-rw-r--r-- | src/backend/catalog/heap.c | 11 | ||||
-rw-r--r-- | src/backend/catalog/index.c | 2 | ||||
-rw-r--r-- | src/backend/catalog/pg_constraint.c | 6 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 28 |
5 files changed, 50 insertions, 5 deletions
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index 72a2c3d3db6..7c5c390503b 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -597,6 +597,8 @@ TupleDescInitEntry(TupleDesc desc, Assert(PointerIsValid(desc)); Assert(attributeNumber >= 1); Assert(attributeNumber <= desc->natts); + Assert(attdim >= 0); + Assert(attdim <= PG_INT16_MAX); /* * initialize the attribute fields @@ -667,6 +669,8 @@ TupleDescInitBuiltinEntry(TupleDesc desc, Assert(PointerIsValid(desc)); Assert(attributeNumber >= 1); Assert(attributeNumber <= desc->natts); + Assert(attdim >= 0); + Assert(attdim <= PG_INT16_MAX); /* initialize the attribute fields */ att = TupleDescAttr(desc, attributeNumber - 1); @@ -827,6 +831,10 @@ BuildDescForRelation(List *schema) attcollation = GetColumnDefCollation(NULL, entry, atttypid); attdim = list_length(entry->typeName->arrayBounds); + if (attdim > PG_INT16_MAX) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many array dimensions")); if (entry->typeName->setof) ereport(ERROR, diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 4f006820b85..2a0d82aedd7 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -732,12 +732,11 @@ InsertPgAttributeTuples(Relation pg_attribute_rel, slot[slotCount]->tts_values[Anum_pg_attribute_attname - 1] = NameGetDatum(&attrs->attname); slot[slotCount]->tts_values[Anum_pg_attribute_atttypid - 1] = ObjectIdGetDatum(attrs->atttypid); - slot[slotCount]->tts_values[Anum_pg_attribute_attstattarget - 1] = Int32GetDatum(attrs->attstattarget); slot[slotCount]->tts_values[Anum_pg_attribute_attlen - 1] = Int16GetDatum(attrs->attlen); slot[slotCount]->tts_values[Anum_pg_attribute_attnum - 1] = Int16GetDatum(attrs->attnum); - slot[slotCount]->tts_values[Anum_pg_attribute_attndims - 1] = Int32GetDatum(attrs->attndims); slot[slotCount]->tts_values[Anum_pg_attribute_attcacheoff - 1] = Int32GetDatum(-1); slot[slotCount]->tts_values[Anum_pg_attribute_atttypmod - 1] = Int32GetDatum(attrs->atttypmod); + slot[slotCount]->tts_values[Anum_pg_attribute_attndims - 1] = Int16GetDatum(attrs->attndims); slot[slotCount]->tts_values[Anum_pg_attribute_attbyval - 1] = BoolGetDatum(attrs->attbyval); slot[slotCount]->tts_values[Anum_pg_attribute_attalign - 1] = CharGetDatum(attrs->attalign); slot[slotCount]->tts_values[Anum_pg_attribute_attstorage - 1] = CharGetDatum(attrs->attstorage); @@ -749,7 +748,8 @@ InsertPgAttributeTuples(Relation pg_attribute_rel, slot[slotCount]->tts_values[Anum_pg_attribute_attgenerated - 1] = CharGetDatum(attrs->attgenerated); slot[slotCount]->tts_values[Anum_pg_attribute_attisdropped - 1] = BoolGetDatum(attrs->attisdropped); slot[slotCount]->tts_values[Anum_pg_attribute_attislocal - 1] = BoolGetDatum(attrs->attislocal); - slot[slotCount]->tts_values[Anum_pg_attribute_attinhcount - 1] = Int32GetDatum(attrs->attinhcount); + slot[slotCount]->tts_values[Anum_pg_attribute_attinhcount - 1] = Int16GetDatum(attrs->attinhcount); + slot[slotCount]->tts_values[Anum_pg_attribute_attstattarget - 1] = Int16GetDatum(attrs->attstattarget); slot[slotCount]->tts_values[Anum_pg_attribute_attcollation - 1] = ObjectIdGetDatum(attrs->attcollation); if (attoptions && attoptions[natts] != (Datum) 0) slot[slotCount]->tts_values[Anum_pg_attribute_attoptions - 1] = attoptions[natts]; @@ -2615,6 +2615,11 @@ MergeWithExistingConstraint(Relation rel, const char *ccname, Node *expr, con->conislocal = true; else con->coninhcount++; + + if (con->coninhcount < 0) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many inheritance parents")); } if (is_no_inherit) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index c64fde4b794..6aec1b1bca2 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1809,7 +1809,7 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName) memset(repl_repl, false, sizeof(repl_repl)); repl_repl[Anum_pg_attribute_attstattarget - 1] = true; - repl_val[Anum_pg_attribute_attstattarget - 1] = Int32GetDatum(attstattarget); + repl_val[Anum_pg_attribute_attstattarget - 1] = Int16GetDatum(attstattarget); newTuple = heap_modify_tuple(attrTuple, RelationGetDescr(pg_attribute), diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c index ce82ede7f90..4002317f705 100644 --- a/src/backend/catalog/pg_constraint.c +++ b/src/backend/catalog/pg_constraint.c @@ -190,7 +190,7 @@ CreateConstraintEntry(const char *constraintName, values[Anum_pg_constraint_confdeltype - 1] = CharGetDatum(foreignDeleteType); values[Anum_pg_constraint_confmatchtype - 1] = CharGetDatum(foreignMatchType); values[Anum_pg_constraint_conislocal - 1] = BoolGetDatum(conIsLocal); - values[Anum_pg_constraint_coninhcount - 1] = Int32GetDatum(conInhCount); + values[Anum_pg_constraint_coninhcount - 1] = Int16GetDatum(conInhCount); values[Anum_pg_constraint_connoinherit - 1] = BoolGetDatum(conNoInherit); if (conkeyArray) @@ -805,6 +805,10 @@ ConstraintSetParentConstraint(Oid childConstrId, constrForm->conislocal = false; constrForm->coninhcount++; + if (constrForm->coninhcount < 0) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many inheritance parents")); constrForm->conparentid = parentConstrId; CatalogTupleUpdate(constrRel, &tuple->t_self, newtup); diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index c510a01fd8d..3147dddf286 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2650,6 +2650,10 @@ MergeAttributes(List *schema, List *supers, char relpersistence, */ def->inhcount++; + if (def->inhcount < 0) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many inheritance parents")); newattmap->attnums[parent_attno - 1] = exist_attno; } @@ -3173,6 +3177,10 @@ MergeCheckConstraint(List *constraints, char *name, Node *expr) { /* OK to merge */ ccon->inhcount++; + if (ccon->inhcount < 0) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many inheritance parents")); return true; } @@ -6828,6 +6836,10 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, /* Bump the existing child att's inhcount */ childatt->attinhcount++; + if (childatt->attinhcount < 0) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many inheritance parents")); CatalogTupleUpdate(attrdesc, &tuple->t_self, tuple); heap_freetuple(tuple); @@ -6919,6 +6931,10 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, attribute.attstattarget = (newattnum > 0) ? -1 : 0; attribute.attlen = tform->typlen; attribute.attnum = newattnum; + if (list_length(colDef->typeName->arrayBounds) > PG_INT16_MAX) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many array dimensions")); attribute.attndims = list_length(colDef->typeName->arrayBounds); attribute.atttypmod = typmod; attribute.attbyval = tform->typbyval; @@ -12924,6 +12940,10 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, attTup->atttypid = targettype; attTup->atttypmod = targettypmod; attTup->attcollation = targetcollid; + if (list_length(typeName->arrayBounds) > PG_INT16_MAX) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many array dimensions")); attTup->attndims = list_length(typeName->arrayBounds); attTup->attlen = tform->typlen; attTup->attbyval = tform->typbyval; @@ -15155,6 +15175,10 @@ MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel) * later on, this change will just roll back.) */ childatt->attinhcount++; + if (childatt->attinhcount < 0) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many inheritance parents")); /* * In case of partitions, we must enforce that value of attislocal @@ -15292,6 +15316,10 @@ MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel) child_copy = heap_copytuple(child_tuple); child_con = (Form_pg_constraint) GETSTRUCT(child_copy); child_con->coninhcount++; + if (child_con->coninhcount < 0) + ereport(ERROR, + errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("too many inheritance parents")); /* * In case of partitions, an inherited constraint must be |