Skip to content

Commit ab7032b

Browse files
committed
Tighten pg_get_object_address argument checking
For publication schemas (OBJECT_PUBLICATION_NAMESPACE) and user mappings (OBJECT_USER_MAPPING), pg_get_object_address() checked the array length of the second argument, but not of the first argument. If the first argument was too long, it would just silently ignore everything but the first argument. Fix that by checking the length of the first argument as well. Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/caaef70b-a874-1088-92ef-5ac38269c33b%40enterprisedb.com
1 parent 1d39552 commit ab7032b

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,10 +2239,16 @@ pg_get_object_address(PG_FUNCTION_ARGS)
22392239
*/
22402240
switch (type)
22412241
{
2242+
case OBJECT_PUBLICATION_NAMESPACE:
2243+
case OBJECT_USER_MAPPING:
2244+
if (list_length(name) != 1)
2245+
ereport(ERROR,
2246+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2247+
errmsg("name list length must be exactly %d", 1)));
2248+
/* fall through to check args length */
2249+
/* FALLTHROUGH */
22422250
case OBJECT_DOMCONSTRAINT:
22432251
case OBJECT_CAST:
2244-
case OBJECT_USER_MAPPING:
2245-
case OBJECT_PUBLICATION_NAMESPACE:
22462252
case OBJECT_PUBLICATION_REL:
22472253
case OBJECT_DEFACL:
22482254
case OBJECT_TRANSFORM:

src/test/regress/expected/object_address.out

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ BEGIN
105105
('text search template'), ('text search configuration'),
106106
('policy'), ('user mapping'), ('default acl'), ('transform'),
107107
('operator of access method'), ('function of access method'),
108-
('publication relation')
108+
('publication namespace'), ('publication relation')
109109
LOOP
110110
FOR names IN VALUES ('{eins}'), ('{addr_nsp, zwei}'), ('{eins, zwei, drei}')
111111
LOOP
@@ -285,10 +285,10 @@ WARNING: error for policy,{eins,zwei,drei},{}: schema "eins" does not exist
285285
WARNING: error for policy,{eins,zwei,drei},{integer}: schema "eins" does not exist
286286
WARNING: error for user mapping,{eins},{}: argument list length must be exactly 1
287287
WARNING: error for user mapping,{eins},{integer}: user mapping for user "eins" on server "integer" does not exist
288-
WARNING: error for user mapping,{addr_nsp,zwei},{}: argument list length must be exactly 1
289-
WARNING: error for user mapping,{addr_nsp,zwei},{integer}: user mapping for user "addr_nsp" on server "integer" does not exist
290-
WARNING: error for user mapping,{eins,zwei,drei},{}: argument list length must be exactly 1
291-
WARNING: error for user mapping,{eins,zwei,drei},{integer}: user mapping for user "eins" on server "integer" does not exist
288+
WARNING: error for user mapping,{addr_nsp,zwei},{}: name list length must be exactly 1
289+
WARNING: error for user mapping,{addr_nsp,zwei},{integer}: name list length must be exactly 1
290+
WARNING: error for user mapping,{eins,zwei,drei},{}: name list length must be exactly 1
291+
WARNING: error for user mapping,{eins,zwei,drei},{integer}: name list length must be exactly 1
292292
WARNING: error for default acl,{eins},{}: argument list length must be exactly 1
293293
WARNING: error for default acl,{eins},{integer}: unrecognized default ACL object type "i"
294294
WARNING: error for default acl,{addr_nsp,zwei},{}: argument list length must be exactly 1
@@ -313,6 +313,12 @@ WARNING: error for function of access method,{addr_nsp,zwei},{}: name list leng
313313
WARNING: error for function of access method,{addr_nsp,zwei},{integer}: name list length must be at least 3
314314
WARNING: error for function of access method,{eins,zwei,drei},{}: argument list length must be exactly 2
315315
WARNING: error for function of access method,{eins,zwei,drei},{integer}: argument list length must be exactly 2
316+
WARNING: error for publication namespace,{eins},{}: argument list length must be exactly 1
317+
WARNING: error for publication namespace,{eins},{integer}: schema "eins" does not exist
318+
WARNING: error for publication namespace,{addr_nsp,zwei},{}: name list length must be exactly 1
319+
WARNING: error for publication namespace,{addr_nsp,zwei},{integer}: name list length must be exactly 1
320+
WARNING: error for publication namespace,{eins,zwei,drei},{}: name list length must be exactly 1
321+
WARNING: error for publication namespace,{eins,zwei,drei},{integer}: name list length must be exactly 1
316322
WARNING: error for publication relation,{eins},{}: argument list length must be exactly 1
317323
WARNING: error for publication relation,{eins},{integer}: relation "eins" does not exist
318324
WARNING: error for publication relation,{addr_nsp,zwei},{}: argument list length must be exactly 1

src/test/regress/sql/object_address.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ BEGIN
9898
('text search template'), ('text search configuration'),
9999
('policy'), ('user mapping'), ('default acl'), ('transform'),
100100
('operator of access method'), ('function of access method'),
101-
('publication relation')
101+
('publication namespace'), ('publication relation')
102102
LOOP
103103
FOR names IN VALUES ('{eins}'), ('{addr_nsp, zwei}'), ('{eins, zwei, drei}')
104104
LOOP

0 commit comments

Comments
 (0)