pgsql: Detect bad input for types xid, xid8, and cid.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Detect bad input for types xid, xid8, and cid.
Date: 2022-12-27 16:40:18
Message-ID: E1pACzy-000gZo-6y@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2022-12-27 17:00:49 pgsql: Convert tsqueryin and tsvectorin to report errors softly.
Previous Message Peter Geoghegan 2022-12-27 07:43:07 pgsql: Remove overzealous MultiXact freeze assertion.