From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Detect bad input for types xid, xid8, and cid.
Date: Tue, 27 Dec 2022 16:40:18 +0000
Message-ID: <E1pACzy-000gZo-6y@gemulon.postgresql.org> (raw)
Detect bad input for types xid, xid8, and cid.
Historically these input functions just called strtoul or strtoull
and returned the result, with no error detection whatever. Upgrade
them to reject garbage input and out-of-range values, similarly to
our other numeric input routines.
To share the code for this with type oid, adjust the existing
"oidin_subr" to be agnostic about the SQL name of the type it is
handling, and move it to numutils.c; then clone it for 64-bit types.
Because the xid types previously accepted hex and octal input by
reason of calling strtoul[l] with third argument zero, I made the
common subroutine do that too, with the consequence that type oid
now also accepts hex and octal input. In view of 6fcda9aba, that
seems like a good thing.
While at it, simplify the existing over-complicated handling of
syntax errors from strtoul: we only need one ereturn not three.
Discussion: https://postgr.es/m/3526121.1672000729@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/eb8312a22a84c33fc405ae9b497113973f552f90
Modified Files
--------------
src/backend/utils/adt/numutils.c | 150 ++++++++++++++++++++++++++++++++++++++
src/backend/utils/adt/oid.c | 101 ++-----------------------
src/backend/utils/adt/xid.c | 12 ++-
src/include/utils/builtins.h | 4 +
src/test/regress/expected/xid.out | 61 ++++++++++++----
src/test/regress/sql/xid.sql | 10 ++-
6 files changed, 222 insertions(+), 116 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Detect bad input for types xid, xid8, and cid.
In-Reply-To: <E1pACzy-000gZo-6y@gemulon.postgresql.org>
References: <E1pACzy-000gZo-6y@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox