agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: pg_dump: avoid assuming how long pg_proc.protrftypes can be.
Date: Mon, 10 Aug 2026 13:41:27 +0000
Message-ID: <E1wtQFr-00000000yCE-0lNm@gemulon.postgresql.org> (raw)

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.mshk@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Backpatch-through: 14
Security: CVE-2026-19385

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c2b16f5d495d977d669c7ec5db07bb666f3691e7
Author: Tom Lane <tgl@sss.pgh.pa.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(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1wtQFr-00000000yCE-0lNm@gemulon.postgresql.org>
Permalink:  ../E1wtQFr-00000000yCE-0lNm@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wtQFr-00000000yCE-0lNm@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: noah@leadboat.com, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: pg_dump: avoid assuming how long pg_proc.protrftypes can be.
  In-Reply-To: <E1wtQFr-00000000yCE-0lNm@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox