aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/schemacmds.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-04-28 19:29:38 +0900
committerMichael Paquier <michael@paquier.xyz>2023-04-28 19:29:38 +0900
commitd29eba1987cb1ae2520e1534e53cc13b720e7e38 (patch)
tree637efa44334d8f3ad97a6484ad9c410971b64bbc /src/backend/commands/schemacmds.c
parent137003036972be4895ccdf802c640d037a5e607e (diff)
downloadpostgresql-d29eba1987cb1ae2520e1534e53cc13b720e7e38.tar.gz
postgresql-d29eba1987cb1ae2520e1534e53cc13b720e7e38.zip
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
Diffstat (limited to 'src/backend/commands/schemacmds.c')
-rw-r--r--src/backend/commands/schemacmds.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c
index 66306d1fd18..ffa42f134fe 100644
--- a/src/backend/commands/schemacmds.c
+++ b/src/backend/commands/schemacmds.c
@@ -178,7 +178,8 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,
* we cannot, in general, run parse analysis on one statement until we
* have actually executed the prior ones.
*/
- parsetree_list = transformCreateSchemaStmt(stmt);
+ parsetree_list = transformCreateSchemaStmtElements(stmt->schemaElts,
+ schemaName);
/*
* Execute each command contained in the CREATE SCHEMA. Since the grammar