pg_dump: Quote not-null constraint names.

When a child table's column is inherited from its parent but the
child has its own not-null constraint on it, pg_dump emits that
constraint as a standalone table constraint in the child's CREATE
TABLE, and it prints the constraint name unquoted.  A name needing
quotes therefore produces broken SQL (or, for a mixed-case name, a
constraint restored under the wrong name), and a name chosen by
the table's owner can inject arbitrary commands into the dump,
which are then run with the privileges of whoever restores it.

To fix, pass the name through fmtId().  Since fmtId() hands back
a pointer into a single shared buffer, the constraint name and
the column name can't be formatted in one appendPQExpBuffer()
call, so the CONSTRAINT clause is printed separately.

Reported-by: Anthropic OSS program
Reported-by: Sarath Kumar <[email protected]>
Reported-by: Nikolay Samokhvalov <[email protected]>
Author: Anthropic OSS program
Reviewed-by: Nathan Bossart <[email protected]>
Reviewed-by: Sami Imseih <[email protected]>
Security: CVE-2026-116318
Backpatch-through: 18

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9e4cde7927da3603a2b6ca0d4e75d50b28888252
Author: Nathan Bossart <[email protected]>

Modified Files
--------------
src/bin/pg_dump/pg_dump.c        | 12 +++++-------
src/bin/pg_dump/t/002_pg_dump.pl |  4 ++--
2 files changed, 7 insertions(+), 9 deletions(-)

Reply via email to