postgresql/src/backend
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
..
access Fix assertion failure in heap_vacuum_rel 2023-04-28 10:30:05 +02:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Fix various typos and incorrect/outdated name references 2023-04-19 13:50:33 +12:00
bootstrap Fix CREATE INDEX progress reporting for multi-level partitioning. 2023-03-25 15:34:03 -04:00
catalog doc: Update SQL features names 2023-04-24 15:39:54 +02:00
commands Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements 2023-04-28 19:29:12 +09:00
executor Fix buffer refcount leak with FDW bulk inserts 2023-04-25 09:42:19 +09:00
foreign De-Revert "Add support for Kerberos credential delegation" 2023-04-13 08:55:07 -04:00
jit Rename ExecAggTransReparent, and improve its documentation. 2023-04-24 13:01:33 -04:00
lib Fix ILIST_DEBUG build 2023-01-18 10:26:15 -08:00
libpq NULL is not an ideal way to spell bool "false". 2023-04-14 13:31:51 -04:00
main Remove obsolete defense against strxfrm() bugs. 2023-04-20 13:20:14 +12:00
nodes Fix list_copy_head() with empty Lists 2023-04-20 10:34:46 +12:00
optimizer Fix various typos and incorrect/outdated name references 2023-04-19 13:50:33 +12:00
parser Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements 2023-04-28 19:29:12 +09:00
partitioning Fix incorrect partition pruning logic for boolean partitioned tables 2023-04-14 16:20:27 +12:00
po meson: add install-{quiet, world} targets 2023-03-23 21:20:18 -07:00
port Update copyright for 2023 2023-01-02 15:00:37 -05:00
postmaster Fix vacuum_cost_delay check for balance calculation. 2023-04-25 13:54:10 +02:00
regex Avoid character classification in regex escape parsing. 2023-04-21 08:19:41 -07:00
replication Use elog to report unexpected action in handle_streamed_transaction(). 2023-04-24 15:37:14 +09:00
rewrite Fix various typos 2023-04-18 13:23:23 +12:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Add SysCacheGetAttrNotNull for guaranteed not-null attrs 2023-03-25 22:49:33 +01:00
storage Remove vacuum_defer_cleanup_age 2023-04-24 12:21:02 -07:00
tcop Handle logical slot conflicts on standby 2023-04-08 00:05:44 -07:00
tsearch Update tsearch regex memory management. 2023-04-08 22:09:17 +12:00
utils Add unit to vacuum_buffer_usage_limit value in postgresql.conf.sample. 2023-04-28 15:40:12 +09:00
.gitignore
Makefile Redesign archive modules 2023-02-17 14:26:42 +09:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
nls.mk NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00