]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
authorMichael Paquier <michael@paquier.xyz>
Fri, 28 Apr 2023 10:29:44 +0000 (19:29 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 28 Apr 2023 10:29:44 +0000 (19:29 +0900)
commita9212716b3bfb8fa83032e5e2e11658f067d7aaf
treef5d84fe1c81435e984326fde526d0df39ead6462
parentc3c1097dc54328b95270dee59bd5709bbf6be8aa
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
src/backend/commands/schemacmds.c
src/backend/parser/parse_utilcmd.c
src/include/parser/parse_utilcmd.h
src/test/regress/expected/create_schema.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/serial_schedule
src/test/regress/sql/create_schema.sql [new file with mode: 0644]