aboutsummaryrefslogtreecommitdiff
path: root/src/fe_utils/option_utils.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2021-07-27 10:39:05 +0900
committerMichael Paquier <michael@paquier.xyz>2021-07-27 10:39:05 +0900
commitf7a9a3d4b24a4ad0de7992f01a0dd2a02ccd30a4 (patch)
treee842018568c7929d3125b7ea9c2f5c1d78bc605f /src/fe_utils/option_utils.c
parent21b3aa9c8faf39ef45a5223681d8947e0a00e7da (diff)
downloadpostgresql-f7a9a3d4b24a4ad0de7992f01a0dd2a02ccd30a4.tar.gz
postgresql-f7a9a3d4b24a4ad0de7992f01a0dd2a02ccd30a4.zip
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
Diffstat (limited to 'src/fe_utils/option_utils.c')
-rw-r--r--src/fe_utils/option_utils.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/fe_utils/option_utils.c b/src/fe_utils/option_utils.c
index 3e7e512ad91..bcfe7365fd3 100644
--- a/src/fe_utils/option_utils.c
+++ b/src/fe_utils/option_utils.c
@@ -57,7 +57,14 @@ option_parse_int(const char *optarg, const char *optname,
errno = 0;
val = strtoint(optarg, &endptr, 10);
- if (*endptr)
+ /*
+ * Skip any trailing whitespace; if anything but whitespace remains before
+ * the terminating character, fail.
+ */
+ while (*endptr != '\0' && isspace((unsigned char) *endptr))
+ endptr++;
+
+ if (*endptr != '\0')
{
pg_log_error("invalid value \"%s\" for option %s",
optarg, optname);