]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Disallow CR and LF in database, role, and tablespace names
authorAndrew Dunstan <andrew@dunslane.net>
Sat, 21 Feb 2026 22:17:48 +0000 (17:17 -0500)
committerAndrew Dunstan <andrew@dunslane.net>
Mon, 23 Feb 2026 16:19:13 +0000 (11:19 -0500)
commitb380a56a3f9556588a89013b765d67947d54f7d0
treef6e05410625600ee5c5add30bf1631ab99c3788b
parent78727dcba32ed374eb2e92df976649bff56e2056
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@gmail.com>
Reviewed-By: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-By: Andrew Dunstan <andrew@dunslane.net>
Reviewed-By: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-By: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-By: Srinath Reddy <srinath2133@gmail.com>
Discussion: https://postgr.es/m/CAKYtNApkOi4FY0S7+3jpTqnHVyyZ6Tbzhtbah-NBbY-mGsiKAQ@mail.gmail.com
15 files changed:
src/backend/commands/dbcommands.c
src/backend/commands/tablespace.c
src/backend/commands/user.c
src/bin/pg_dump/t/002_pg_dump.pl
src/bin/pg_dump/t/003_pg_dump_with_server.pl
src/bin/pg_dump/t/010_dump_connstr.pl
src/bin/pg_upgrade/check.c
src/bin/scripts/t/020_createdb.pl
src/fe_utils/string_utils.c
src/test/modules/unsafe_tests/expected/alter_system_table.out
src/test/modules/unsafe_tests/expected/rolenames.out
src/test/modules/unsafe_tests/sql/alter_system_table.sql
src/test/modules/unsafe_tests/sql/rolenames.sql
src/test/regress/expected/tablespace.out
src/test/regress/sql/tablespace.sql