pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
6+ messages / 1 participants
[nested] [flat]

* pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
@ 2023-04-28 10:30  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Paquier @ 2023-04-28 10:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b9ad73ad250bc278d52d4383b0f3972997a43906

Modified Files
--------------
src/backend/commands/schemacmds.c           |  3 +-
src/backend/parser/parse_utilcmd.c          | 38 +++++------
src/include/parser/parse_utilcmd.h          |  3 +-
src/test/regress/expected/create_schema.out | 98 +++++++++++++++++++++++++++++
src/test/regress/parallel_schedule          |  2 +-
src/test/regress/sql/create_schema.sql      | 70 +++++++++++++++++++++
6 files changed, 192 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
@ 2023-04-28 10:30  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Paquier @ 2023-04-28 10:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/63f7e91ecf9fd21d6e4d4427787fef04585961fe

Modified Files
--------------
src/backend/commands/schemacmds.c           |  3 +-
src/backend/parser/parse_utilcmd.c          | 38 +++++------
src/include/parser/parse_utilcmd.h          |  3 +-
src/test/regress/expected/create_schema.out | 98 +++++++++++++++++++++++++++++
src/test/regress/parallel_schedule          |  2 +-
src/test/regress/serial_schedule            |  1 +
src/test/regress/sql/create_schema.sql      | 70 +++++++++++++++++++++
7 files changed, 193 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
@ 2023-04-28 10:30  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Paquier @ 2023-04-28 10:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7e95a33b42e76d34053bfc9c2845d43753a2e7b3

Modified Files
--------------
src/backend/commands/schemacmds.c           |  3 +-
src/backend/parser/parse_utilcmd.c          | 38 +++++------
src/include/parser/parse_utilcmd.h          |  3 +-
src/test/regress/expected/create_schema.out | 98 +++++++++++++++++++++++++++++
src/test/regress/parallel_schedule          |  2 +-
src/test/regress/serial_schedule            |  1 +
src/test/regress/sql/create_schema.sql      | 70 +++++++++++++++++++++
7 files changed, 193 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
@ 2023-04-28 10:30  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Paquier @ 2023-04-28 10:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a9212716b3bfb8fa83032e5e2e11658f067d7aaf

Modified Files
--------------
src/backend/commands/schemacmds.c           |  3 +-
src/backend/parser/parse_utilcmd.c          | 38 +++++------
src/include/parser/parse_utilcmd.h          |  3 +-
src/test/regress/expected/create_schema.out | 98 +++++++++++++++++++++++++++++
src/test/regress/parallel_schedule          |  2 +-
src/test/regress/serial_schedule            |  1 +
src/test/regress/sql/create_schema.sql      | 70 +++++++++++++++++++++
7 files changed, 193 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
@ 2023-04-28 10:30  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Paquier @ 2023-04-28 10:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4dadd660f0719206ce3914d4ad9b6aad69d6db6e

Modified Files
--------------
src/backend/commands/schemacmds.c           |  3 +-
src/backend/parser/parse_utilcmd.c          | 38 +++++------
src/include/parser/parse_utilcmd.h          |  3 +-
src/test/regress/expected/create_schema.out | 98 +++++++++++++++++++++++++++++
src/test/regress/parallel_schedule          |  2 +-
src/test/regress/sql/create_schema.sql      | 70 +++++++++++++++++++++
6 files changed, 192 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements
@ 2023-04-28 10:30  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Paquier @ 2023-04-28 10:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d29eba1987cb1ae2520e1534e53cc13b720e7e38

Modified Files
--------------
src/backend/commands/schemacmds.c           |  3 +-
src/backend/parser/parse_utilcmd.c          | 38 +++++------
src/include/parser/parse_utilcmd.h          |  3 +-
src/test/regress/expected/create_schema.out | 98 +++++++++++++++++++++++++++++
src/test/regress/parallel_schedule          |  2 +-
src/test/regress/sql/create_schema.sql      | 70 +++++++++++++++++++++
6 files changed, 192 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2023-04-28 10:30 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 10:30 pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements Michael Paquier <michael@paquier.xyz>
2023-04-28 10:30 pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements Michael Paquier <michael@paquier.xyz>
2023-04-28 10:30 pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements Michael Paquier <michael@paquier.xyz>
2023-04-28 10:30 pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements Michael Paquier <michael@paquier.xyz>
2023-04-28 10:30 pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements Michael Paquier <michael@paquier.xyz>
2023-04-28 10:30 pgsql: Fix crashes with CREATE SCHEMA AUTHORIZATION and schema elements Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox