pgsql: Disallow CR and LF in database, role, and tablespace names

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Disallow CR and LF in database, role, and tablespace names
Date: 2026-02-23 16:20:21
Message-ID: E1vuYfV-000qgc-2C@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Disallow CR and LF in database, role, and tablespace names

Previously, these characters could cause problems when passed through
shell commands, and were flagged with a comment in string_utils.c
suggesting they be rejected in a future major release.

The affected commands are CREATE DATABASE, CREATE ROLE, CREATE TABLESPACE,
ALTER DATABASE RENAME, ALTER ROLE RENAME, and ALTER TABLESPACE RENAME.

Also add a pg_upgrade check to detect these invalid names in clusters
being upgraded from pre-v19 versions, producing a report file listing
any offending objects that must be renamed before upgrading.

Tests have been modified accordingly.

Author: Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>
Reviewed-By: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Reviewed-By: Andrew Dunstan <andrew(at)dunslane(dot)net>
Reviewed-By: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-By: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Reviewed-By: Srinath Reddy <srinath2133(at)gmail(dot)com>

Discussion: https://postgr.es/m/CAKYtNApkOi4FY0S7+3jpTqnHVyyZ6Tbzhtbah-NBbY-mGsiKAQ@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/commands/dbcommands.c | 12 ++++
src/backend/commands/tablespace.c | 12 ++++
src/backend/commands/user.c | 12 ++++
src/bin/pg_dump/t/002_pg_dump.pl | 9 +--
src/bin/pg_dump/t/003_pg_dump_with_server.pl | 16 -----
src/bin/pg_dump/t/010_dump_connstr.pl | 14 ----
src/bin/pg_upgrade/check.c | 79 ++++++++++++++++++++++
src/bin/scripts/t/020_createdb.pl | 12 ++++
src/fe_utils/string_utils.c | 6 --
.../unsafe_tests/expected/alter_system_table.out | 5 ++
.../modules/unsafe_tests/expected/rolenames.out | 4 ++
.../unsafe_tests/sql/alter_system_table.sql | 4 ++
src/test/modules/unsafe_tests/sql/rolenames.sql | 2 +
src/test/regress/expected/tablespace.out | 5 ++
src/test/regress/sql/tablespace.sql | 4 ++
15 files changed, 153 insertions(+), 43 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-02-23 16:32:35 pgsql: Flip logic in table validate_relation_kind
Previous Message Peter Eisentraut 2026-02-23 16:13:29 Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)