agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix optional-argument handling in in-tree getopt_long().
Date: Fri, 11 Sep 2026 19:38:29 +0000
Message-ID: <E1x574u-00000004Tlh-2T44@gemulon.postgresql.org> (raw)
Fix optional-argument handling in in-tree getopt_long().
If a long option that accepts an optional argument is given without
one, optind is advanced twice, and the following argument is
skipped. For example, "pg_waldump --stats --limit 5" skips --limit
and interprets "5" as a non-option, so the command complains that
it cannot location WAL file "5". The same path also returns BADARG
when optstring starts with a colon, even though nothing is missing.
To fix, handle optional arguments before the missing-argument code,
which then only needs to deal with required arguments.
This is a bug fix and could be back-patched, but since this issue
went unnoticed for 23 years, I'm not going to bother.
Author: Sehrope Sarkuni <sehrope@jackdb.com>
Reviewed-by: solai v <solai.cdac@gmail.com>
Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/61aa17b92eab017d64419c19fa466d72a509d016
Modified Files
--------------
src/bin/pg_waldump/t/001_basic.pl | 3 +--
src/port/getopt_long.c | 11 +++++------
2 files changed, 6 insertions(+), 8 deletions(-)
Message-ID: <E1x574u-00000004Tlh-2T44@gemulon.postgresql.org>
Permalink: ../E1x574u-00000004Tlh-2T44@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1x574u-00000004Tlh-2T44@gemulon.postgresql.org
reply
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 using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: nathan@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix optional-argument handling in in-tree getopt_long().
In-Reply-To: <E1x574u-00000004Tlh-2T44@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox