pgsql: Tighten tid input parsing with strtoul() to reject empty fields

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Tighten tid input parsing with strtoul() to reject empty fields
Date: 2026-08-06 06:41:09
Message-ID: E1wrrmv-00000000OoN-38uf@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Tighten tid input parsing with strtoul() to reject empty fields

strtoul() informs that in the case of no conversion, "endptr" is set
equal to the location of the input pointer, which is something that
tidin() has never checked.

This allowed inputs like "(,)", "(1,)" or "(,1)" to be accepted on some
platforms, like Linux where "(1,)" implied "(1,0)", but rejected on
others like macos where "(1,)" is rejected, due to the fact that errno
may not be set.

This change may cause some issues as some tid values will now be
rejected, but at least we get the consistent strtoul() experience.
If it proves to be a pain for some, it could always be reverted.
Another point of this change is that we get one step closer to a
possible common strtoul() where the error handling could be unified in
core, with all the errors handled the same way for errno and no input
parsed, at least.

Reported-by: Michael Malis <malis(at)pgrust(dot)com>
Author: Tristan Partin <tristan(at)partin(dot)io>
Discussion: https://postgr.es/m/19584-e60c446ba6f57c9c@postgresql.org
Discussion: https://postgr.es/m/DKBS2Z9CGARC.2T07O6TJYSE8B@partin.io

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/58ff4a0a08679356e502dfcbbc50e9bec94b77b1

Modified Files
--------------
src/backend/utils/adt/tid.c | 5 ++---
src/test/regress/expected/tid.out | 8 ++++++++
src/test/regress/sql/tid.sql | 2 ++
3 files changed, 12 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-08-06 07:59:49 pgsql: Tighten proto_version parsing in pgoutput
Previous Message Amit Kapila 2026-08-06 06:17:47 pgsql: Fix race condition in subscription TAP test 023_twophase_stream.