pgsql: Fix inconsistent quoting of role names in ACLs.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix inconsistent quoting of role names in ACLs.
Date: 2025-07-11 22:50:33
Message-ID: E1uaMZd-005pLV-29@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix inconsistent quoting of role names in ACLs.

getid() and putid(), which parse and deparse role names within ACL
input/output, applied isalnum() to see if a character within a role
name requires quoting. They did this even for non-ASCII characters,
which is problematic because the results would depend on encoding,
locale, and perhaps even platform. So it's possible that putid()
could elect not to quote some string that, later in some other
environment, getid() will decide is not a valid identifier, causing
dump/reload or similar failures.

To fix this in a way that won't risk interoperability problems
with unpatched versions, make getid() treat any non-ASCII as a
legitimate identifier character (hence not requiring quotes),
while making putid() treat any non-ASCII as requiring quoting.
We could remove the resulting excess quoting once we feel that
no unpatched servers remain in the wild, but that'll be years.

A lesser problem is that getid() did the wrong thing with an input
consisting of just two double quotes (""). That has to represent an
empty string, but getid() read it as a single double quote instead.
The case cannot arise in the normal course of events, since we don't
allow empty-string role names. But let's fix it while we're here.

Although we've not heard field reports of problems with non-ASCII
role names, there's clearly a hazard there, so back-patch to all
supported versions.

Reported-by: Peter Eisentraut <peter(at)eisentraut(dot)org>
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/3792884.1751492172@sss.pgh.pa.us
Backpatch-through: 13

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/093d3d74576e1e60212622dbaeeb3eb2b184fbf3

Modified Files
--------------
src/backend/utils/adt/acl.c | 33 ++++++++++++++++++++++++--------
src/test/regress/expected/privileges.out | 20 +++++++++++++++++++
src/test/regress/sql/privileges.sql | 8 ++++++++
3 files changed, 53 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2025-07-12 01:33:05 pgsql: Fix stale idle flag when IO workers exit.
Previous Message Jacob Champion 2025-07-11 17:32:42 pgsql: oauth: Run Autoconf tests with correct compiler flags