Disallow CR and LF in database, role, and tablespace names
Andrew Dunstan <andrew@dunslane.net>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/commands/dbcommands.c | modified | +12 −0 |
| src/backend/commands/tablespace.c | modified | +12 −0 |
| src/backend/commands/user.c | modified | +12 −0 |
| src/bin/pg_dump/t/002_pg_dump.pl | modified | +2 −7 |
| src/bin/pg_dump/t/003_pg_dump_with_server.pl | modified | +0 −16 |
| src/bin/pg_dump/t/010_dump_connstr.pl | modified | +0 −14 |
| src/bin/pg_upgrade/check.c | modified | +79 −0 |
| src/bin/scripts/t/020_createdb.pl | modified | +12 −0 |
| src/fe_utils/string_utils.c | modified | +0 −6 |
| src/test/modules/unsafe_tests/expected/alter_system_table.out | modified | +5 −0 |
| src/test/modules/unsafe_tests/expected/rolenames.out | modified | +4 −0 |
| src/test/modules/unsafe_tests/sql/alter_system_table.sql | modified | +4 −0 |
| src/test/modules/unsafe_tests/sql/rolenames.sql | modified | +2 −0 |
| src/test/regress/expected/tablespace.out | modified | +5 −0 |
| src/test/regress/sql/tablespace.sql | modified | +4 −0 |
Discussion
- getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote 48 messages · 2025-01-29 → 2026-02-24