postgresql/src/include/parser
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
..
analyze.h Move queryjumble.c code to src/backend/nodes/ 2023-01-21 11:48:37 +09:00
kwlist.h SQL/JSON: support the IS JSON predicate 2023-03-31 22:34:04 +02:00
parse_agg.h Allow parallel aggregate on string_agg and array_agg 2023-01-23 17:35:01 +13:00
parse_clause.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_coerce.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_collate.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_cte.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_enr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_expr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_func.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_merge.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_node.h Make Vars be outer-join-aware. 2023-01-30 13:16:20 -05:00
parse_oper.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_param.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_relation.h Make Vars be outer-join-aware. 2023-01-30 13:16:20 -05:00
parse_target.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_type.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parse_utilcmd.h Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements 2023-04-28 19:29:12 +09:00
parser.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
parsetree.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
scanner.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
scansup.h Update copyright for 2023 2023-01-02 15:00:37 -05:00