pgsql: Detect bad input for types xid, xid8, and cid. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Detect bad input for types xid, xid8, and cid.
Date
Msg-id E1pACzy-000gZo-6y@gemulon.postgresql.org
Whole thread Raw
List 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(-)


pgsql-committers by date:

Previous
From: Peter Geoghegan
Date:
Subject: pgsql: Remove overzealous MultiXact freeze assertion.
Next
From: Tom Lane
Date:
Subject: pgsql: Convert tsqueryin and tsvectorin to report errors softly.