agora inbox for pgsql-hackers@postgresql.orghelp / color / mirror / Atom feed
[PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). 152+ messages / 1 participants [nested] [flat]
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
* [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). @ 2026-09-04 21:37 Nathan Bossart <nathan@postgresql.org> 0 siblings, 0 replies; 152+ messages in thread From: Nathan Bossart @ 2026-09-04 21:37 UTC (permalink / raw) A long option with an optional argument that is given without "=" advances optind twice, so the following argument is skipped. For example, "pg_waldump --stats --limit 5" complains that it cannot locate 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> Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 3 +-- src/port/getopt_long.c | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 8beac19eaff..7b33efc6299 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -340,11 +340,10 @@ sub test_pg_waldump my ($stdout, $stderr); my $result = IPC::Run::run [ - 'pg_waldump', + 'pg_waldump', @opts, '--start' => $startlsn, '--end' => $endlsn, '--path' => $path, - @opts ], '>' => \$stdout, '2>' => \$stderr; diff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 2e869fed58b..0a9a50189f1 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -137,8 +137,9 @@ retry: { if (place[namelen] == '=') optarg = place + namelen + 1; - else if (optind < argc - 1 && - has_arg == required_argument) + else if (has_arg == optional_argument) + optarg = NULL; + else if (optind < argc - 1) { optind++; optarg = argv[optind]; @@ -152,16 +153,14 @@ retry: return BADARG; } - if (opterr && has_arg == required_argument) + if (opterr) fprintf(stderr, "%s: option requires an argument -- %s\n", argv[0], place); place = EMSG; - if (has_arg == required_argument) - return BADCH; - optarg = NULL; + return BADCH; } } else -- 2.55.0 --Zv9Xg0nwk4TTIGFg Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0002-Fix-option-argument-lookup-in-in-tree-getopt_long.patch ^ permalink raw reply [nested|flat] 152+ messages in thread
end of thread, other threads:[~2026-09-04 21:37 UTC | newest] Thread overview: 152+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org> 2026-09-04 21:37 [PATCH v2 1/2] Fix optional-argument handling in in-tree getopt_long(). Nathan Bossart <nathan@postgresql.org>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox