Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f7a9a3d

Browse files
committed
Skip trailing whitespaces when parsing integer options
strtoint(), via strtol(), would skip leading whitespaces but the same rule was not applied for trailing whitespaces, leading to an inconsistent behavior. Some tests are changed to cover more this area. Author: Michael Paquier Reviewed-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/YP5Pv0d13Ct+03ve@paquier.xyz
1 parent 21b3aa9 commit f7a9a3d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/bin/pg_basebackup/t/020_pg_receivewal.pl

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@
8888
$primary->psql('postgres',
8989
'INSERT INTO test_table VALUES (generate_series(100,200));');
9090

91+
# Note the trailing whitespace after the value of --compress, that is
92+
# a valid value.
9193
$primary->command_ok(
9294
[
9395
'pg_receivewal', '-D', $stream_dir, '--verbose',
94-
'--endpos', $nextlsn, '--compress', '1'
96+
'--endpos', $nextlsn, '--compress', '1 '
9597
],
9698
"streaming some WAL using ZLIB compression");
9799

src/bin/pg_dump/t/001_basic.pl

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@
101101
qr/\Qpg_dump: error: parallel backup only supported by the directory format\E/,
102102
'pg_dump: parallel backup only supported by the directory format');
103103

104+
# Note the trailing whitespace for the value of --jobs, that is valid.
104105
command_fails_like(
105-
[ 'pg_dump', '-j', '-1' ],
106+
[ 'pg_dump', '-j', '-1 ' ],
106107
qr/\Qpg_dump: error: -j\/--jobs must be in range\E/,
107108
'pg_dump: -j/--jobs must be in range');
108109

src/fe_utils/option_utils.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ option_parse_int(const char *optarg, const char *optname,
5757
errno = 0;
5858
val = strtoint(optarg, &endptr, 10);
5959

60-
if (*endptr)
60+
/*
61+
* Skip any trailing whitespace; if anything but whitespace remains before
62+
* the terminating character, fail.
63+
*/
64+
while (*endptr != '\0' && isspace((unsigned char) *endptr))
65+
endptr++;
66+
67+
if (*endptr != '\0')
6168
{
6269
pg_log_error("invalid value \"%s\" for option %s",
6370
optarg, optname);

0 commit comments

Comments
 (0)