diff options
author | Álvaro Herrera <alvherre@alvh.no-ip.org> | 2024-10-10 17:41:01 +0200 |
---|---|---|
committer | Álvaro Herrera <alvherre@alvh.no-ip.org> | 2024-10-10 17:41:01 +0200 |
commit | fd64ed60b62697984bb69a09a3ae19fbe2905eb6 (patch) | |
tree | 5ee6945b4ba985633a3aa69cfe77adcf32331d04 /src/include | |
parent | 1909835c28a144bf957254eea1f4a4dabafbbaee (diff) | |
download | postgresql-fd64ed60b62697984bb69a09a3ae19fbe2905eb6.tar.gz postgresql-fd64ed60b62697984bb69a09a3ae19fbe2905eb6.zip |
Unbreak overflow test for attinhcount/coninhcount
Commit 90189eefc1e1 narrowed pg_attribute.attinhcount and
pg_constraint.coninhcount from 32 to 16 bits, but kept other related
structs with 32-bit wide fields: ColumnDef and CookedConstraint contain
an int 'inhcount' field which is itself checked for overflow on
increments, but there's no check that the values aren't above INT16_MAX
before assigning to the catalog columns. This means that a creative
user can get a inconsistent table definition and override some
protections.
Fix it by changing those other structs to also use int16.
Also, modernize style by using pg_add_s16_overflow for overflow testing
instead of checking for negative values.
We also have Constraint.inhcount, which is here removed completely.
This was added by commit b0e96f311985 and not removed by its revert at
6f8bb7c1e961. It is not needed by the upcoming not-null constraints
patch.
This is mostly academic, so we agreed not to backpatch to avoid ABI
problems.
Bump catversion because of the changes to parse nodes.
Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Co-authored-by: 何建 (jian he) <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/202410081611.up4iyofb5ie7@alvherre.pgsql
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
-rw-r--r-- | src/include/catalog/heap.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_constraint.h | 2 | ||||
-rw-r--r-- | src/include/nodes/parsenodes.h | 4 |
4 files changed, 4 insertions, 6 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 8cdb8c5d6c6..8cb918d9116 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -57,6 +57,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202410111 +#define CATALOG_VERSION_NO 202410112 #endif diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h index c512824cd1c..d6a2c791290 100644 --- a/src/include/catalog/heap.h +++ b/src/include/catalog/heap.h @@ -41,7 +41,7 @@ typedef struct CookedConstraint Node *expr; /* transformed default or check expr */ bool skip_validation; /* skip validation? (only for CHECK) */ bool is_local; /* constraint has local (non-inherited) def */ - int inhcount; /* number of times constraint is inherited */ + int16 inhcount; /* number of times constraint is inherited */ bool is_no_inherit; /* constraint has local def and cannot be * inherited */ } CookedConstraint; diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h index 115217a6162..35788315bc4 100644 --- a/src/include/catalog/pg_constraint.h +++ b/src/include/catalog/pg_constraint.h @@ -245,7 +245,7 @@ extern Oid CreateConstraintEntry(const char *constraintName, Node *conExpr, const char *conBin, bool conIsLocal, - int conInhCount, + int16 conInhCount, bool conNoInherit, bool conPeriod, bool is_internal); diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 1c314cd9074..5b62df32733 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -728,7 +728,7 @@ typedef struct ColumnDef char *colname; /* name of column */ TypeName *typeName; /* type of column */ char *compression; /* compression method for column */ - int inhcount; /* number of times column is inherited */ + int16 inhcount; /* number of times column is inherited */ bool is_local; /* column has local (non-inherited) def'n */ bool is_not_null; /* NOT NULL constraint specified? */ bool is_from_type; /* column definition came from table type */ @@ -2754,8 +2754,6 @@ typedef struct Constraint char *cooked_expr; /* CHECK or DEFAULT expression, as * nodeToString representation */ char generated_when; /* ALWAYS or BY DEFAULT */ - int inhcount; /* initial inheritance count to apply, for - * "raw" NOT NULL constraints */ bool nulls_not_distinct; /* null treatment for UNIQUE constraints */ List *keys; /* String nodes naming referenced key * column(s); for UNIQUE/PK/NOT NULL */ |