pgsql: pg_dump: avoid assuming how long pg_proc.protrftypes can be.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pg_dump: avoid assuming how long pg_proc.protrftypes can be.
Date: 2026-08-10 13:41:19
Message-ID: E1wtQFj-00000000y0p-3Y7w@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

pg_dump: avoid assuming how long pg_proc.protrftypes can be.

The backend doesn't impose any particular limit on the length of this
array, and since there could be entries for both input and output
arguments, it's feasible for the length to exceed FUNC_MAX_ARGS
even without funny business. This could lead to crashes or worse.

Moreover, pg_dump shouldn't rely on hard-coding FUNC_MAX_ARGS in the
first place: it has no business assuming that the backend it's dumping
from was compiled with the same value of FUNC_MAX_ARGS that it is.
So the stanza in dumpFunc() that allocates exactly FUNC_MAX_ARGS space
for the parsed OID array is fundamentally misguided. And it's broken
in another way too: if there are exactly FUNC_MAX_ARGS OIDs, then
parseOidArray won't zero-fill any entries, allowing the subsequent
loop to run off the end of the array. A crash seems unlikely in
this variant, but garbage output is certain.

To fix, redesign parseOidArray's API so that it does the
array-mallocing, which simplifies the callers anyway. While we're
here, tighten and modernize it a bit; in particular, split it into
separate functions for OIDs and integers, as was foreseen long ago.
This lets us get rid of the confusing type-punning involved in
having IndxInfo.indkeys be declared as "Oid *" when it's really
potentially-signed ints. Also, most of the callers expect an exact
number of array entries, so make it verify that not just check for
"too many".

I noted while testing that this dumpFunc() stanza isn't even reached
during check-world. Add a function with transform to the regression
tests to rectify that.

Reported-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Backpatch-through: 14
Security: CVE-2026-19385

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/13bb73aeb688632872d9866c60be8839cdc1f599
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

Modified Files
--------------
src/bin/pg_dump/common.c | 142 ++++++++++++++++++++++-----
src/bin/pg_dump/pg_dump.c | 30 ++----
src/bin/pg_dump/pg_dump.h | 5 +-
src/test/regress/expected/object_address.out | 4 +
src/test/regress/sql/object_address.sql | 4 +
5 files changed, 140 insertions(+), 45 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-08-10 13:41:20 pgsql: Fix pg_trgm's picksplit function with all-true datums
Previous Message John Naylor 2026-08-10 10:40:03 Re: pgsql: Rename sort support integer comparators for clarity