pgsql: pg_resetwal: Reject negative and out of range arguments

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pg_resetwal: Reject negative and out of range arguments
Date: 2025-12-08 14:56:17
Message-ID: E1vSceu-003Rvk-1d@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

pg_resetwal: Reject negative and out of range arguments

The strtoul() function that we used to parse many of the options
accepts negative values, and silently wraps them to the equivalent
unsigned values. For example, -1 becomes 0xFFFFFFFF, on platforms
where unsigned long is 32 bits wide. Also, on platforms where
"unsigned long" is 64 bits wide, we silently casted values larger than
UINT32_MAX to the equivalent 32-bit value. Both of those behaviors
seem undesirable, so tighten up the parsing to reject them.

Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/81adf5f3-36ad-4bcd-9ba5-1b95c7b7a807@iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/636c1914b483bab0eaabdec30cf1f2c743606d7f

Modified Files
--------------
src/bin/pg_resetwal/pg_resetwal.c | 64 ++++++++++++++++++++++++++++++--------
src/bin/pg_resetwal/t/001_basic.pl | 32 ++++++++++++++++---
2 files changed, 78 insertions(+), 18 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2025-12-08 15:32:15 pgsql: Unify error messages
Previous Message Peter Eisentraut 2025-12-08 14:54:27 pgsql: Make ecpg parse.pl more robust with braces