Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2da8c4c

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 3d4e841 commit 2da8c4c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/backend/catalog/objectaddress.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -2254,10 +2254,16 @@ pg_get_object_address(PG_FUNCTION_ARGS)
22542254
*/
22552255
switch (type)
22562256
{
2257+
case OBJECT_PUBLICATION_NAMESPACE:
2258+
case OBJECT_USER_MAPPING:
2259+
if (list_length(name) != 1)
2260+
ereport(ERROR,
2261+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2262+
errmsg("name list length must be exactly %d", 1)));
2263+
/* fall through to check args length */
2264+
/* FALLTHROUGH */
22572265
case OBJECT_DOMCONSTRAINT:
22582266
case OBJECT_CAST:
2259-
case OBJECT_USER_MAPPING:
2260-
case OBJECT_PUBLICATION_NAMESPACE:
22612267
case OBJECT_PUBLICATION_REL:
22622268
case OBJECT_DEFACL:
22632269
case OBJECT_TRANSFORM:

src/test/regress/expected/object_address.out

+11-5
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

+1-1
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)