From 005366510e8360f750212d77d2a9e9a842846c1f Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Fri, 27 Nov 2026 14:03:51 +0800 Subject: [PATCH v1] Reject empty and whitespace-only integer option values When strtoint() consumes no digits, it returns zero and leaves the end pointer at the start of the input. option_parse_int() skipped trailing whitespace before checking the end pointer, so it accepted empty and whitespace-only arguments as zero for options whose range includes zero. Check whether strtoint() consumed any digits before skipping trailing whitespace. Add regression tests for both cases using pg_dump's --extra-float-digits option. Author: Chao Li --- src/bin/pg_dump/t/001_basic.pl | 10 ++++++++++ src/fe_utils/option_utils.c | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/bin/pg_dump/t/001_basic.pl b/src/bin/pg_dump/t/001_basic.pl index b2558046224..be623f62160 100644 --- a/src/bin/pg_dump/t/001_basic.pl +++ b/src/bin/pg_dump/t/001_basic.pl @@ -192,6 +192,16 @@ command_fails_like( qr/\Qpg_dump: error: --extra-float-digits must be in range\E/, 'pg_dump: --extra-float-digits must be in range'); +command_fails_like( + [ 'pg_dump', '--extra-float-digits=' ], + qr/\Qpg_dump: error: invalid value "" for option --extra-float-digits\E/, + 'pg_dump: reject empty --extra-float-digits'); + +command_fails_like( + [ 'pg_dump', '--extra-float-digits= ' ], + qr/\Qpg_dump: error: invalid value " " for option --extra-float-digits\E/, + 'pg_dump: reject whitespace-only --extra-float-digits'); + command_fails_like( [ 'pg_dump', '--rows-per-insert', '0' ], qr/\Qpg_dump: error: --rows-per-insert must be in range\E/, diff --git a/src/fe_utils/option_utils.c b/src/fe_utils/option_utils.c index c8bba075c1f..a6390381b3d 100644 --- a/src/fe_utils/option_utils.c +++ b/src/fe_utils/option_utils.c @@ -57,6 +57,13 @@ option_parse_int(const char *optarg, const char *optname, errno = 0; val = strtoint(optarg, &endptr, 10); + if (endptr == optarg) + { + pg_log_error("invalid value \"%s\" for option %s", + optarg, optname); + return false; + } + /* * Skip any trailing whitespace; if anything but whitespace remains before * the terminating character, fail. -- 2.50.1 (Apple Git-155)