postgresql/src/backend/commands
Michael Paquier 4dadd660f0 Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
CREATE SCHEMA AUTHORIZATION with appended schema elements can lead to
crashes when comparing the schema name of the query with the schemas
used in the qualification of some clauses in the elements' queries.

The origin of the problem is that the transformation routine for the
elements listed in a CREATE SCHEMA query uses as new, expected, schema
name the one listed in CreateSchemaStmt itself.  However, depending on
the query, CreateSchemaStmt.schemaname may be NULL, being computed
instead from the role specification of the query given by the
AUTHORIZATION clause, that could be either:
- A user name string, with the new schema name being set to the same
value as the role given.
- Guessed from CURRENT_ROLE, SESSION_ROLE or CURRENT_ROLE, with a new
schema name computed from the security context where CREATE SCHEMA is
running.

Regression tests are added for CREATE SCHEMA with some appended elements
(some of them with schema qualifications), covering also some role
specification patterns.

While on it, this simplifies the context structure used during the
transformation of the elements listed in a CREATE SCHEMA query by
removing the fields for the role specification and the role type.  They
were not used, and for the role specification this could be confusing as
the schema name may by extracted from that at the beginning of
CreateSchemaCommand().

This issue exists for a long time, so backpatch down to all the versions
supported.

Reported-by: Song Hongyu
Author: Michael Paquier
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/17909-f65c12dfc5f0451d@postgresql.org
Backpatch-through: 11
2023-04-28 19:29:12 +09:00
..
Makefile Move parallel vacuum code to vacuumparallel.c. 2021-12-23 11:42:52 +05:30
aggregatecmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
alter.c Add new predefined role pg_create_subscription. 2023-03-30 11:37:19 -04:00
amcmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
analyze.c Move heaprel struct field next to index rel field. 2023-04-03 11:01:11 -07:00
async.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
cluster.c Fix MAINTAIN privileges for toast tables and partitions. 2023-01-14 00:16:23 -08:00
collationcmds.c Canonicalize ICU locale names to language tags. 2023-04-04 10:38:58 -07:00
comment.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
constraint.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
conversioncmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
copy.c Improve several permission-related error messages. 2023-03-17 10:33:09 +01:00
copyfrom.c Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
copyfromparse.c Don't try to read default for a non-existent attribute 2023-03-15 17:20:42 -04:00
copyto.c Simplify useless 0L constants 2023-03-29 08:25:12 +02:00
createas.c Simplify useless 0L constants 2023-03-29 08:25:12 +02:00
dbcommands.c Canonicalize ICU locale names to language tags. 2023-04-04 10:38:58 -07:00
define.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
discard.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
dropcmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
event_trigger.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
explain.c Support "Right Anti Join" plan shapes. 2023-04-05 16:59:09 -04:00
extension.c Add @extschema:name@ and no_relocate options to extensions. 2023-03-20 18:37:11 -04:00
foreigncmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
functioncmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
indexcmds.c Add SysCacheGetAttrNotNull for guaranteed not-null attrs 2023-03-25 22:49:33 +01:00
lockcmds.c Get rid of the "new" and "old" entries in a view's rangetable. 2023-01-18 13:23:57 -05:00
matview.c Simplify useless 0L constants 2023-03-29 08:25:12 +02:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00
opclasscmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
operatorcmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
policy.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
portalcmds.c Simplify useless 0L constants 2023-03-29 08:25:12 +02:00
prepare.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
proclang.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
publicationcmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
schemacmds.c Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements 2023-04-28 19:29:12 +09:00
seclabel.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
sequence.c Convert many uses of ReadBuffer[Extended](P_NEW) to ExtendBufferedRel() 2023-04-05 18:57:29 -07:00
statscmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
subscriptioncmds.c Remove some tabs in SQL code in C string literals 2023-04-19 09:29:43 +02:00
tablecmds.c Comment fix for 60684dd834. 2023-04-17 13:45:50 -07:00
tablespace.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
trigger.c Fix another issue with ENABLE/DISABLE TRIGGER on partitioned tables. 2023-04-05 12:56:32 -04:00
tsearchcmds.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
typecmds.c Add SysCacheGetAttrNotNull for guaranteed not-null attrs 2023-03-25 22:49:33 +01:00
user.c Fix typo 2023-03-17 21:40:25 +01:00
vacuum.c Improve ereports for VACUUM's BUFFER_USAGE_LIMIT option 2023-04-11 19:36:34 +12:00
vacuumparallel.c Fix various typos and incorrect/outdated name references 2023-04-19 13:50:33 +12:00
variable.c Fix outdated references to guc.c 2023-03-02 13:49:39 +01:00
view.c Get rid of the "new" and "old" entries in a view's rangetable. 2023-01-18 13:23:57 -05:00