diff options
author | Phil Sutter <phil@nwl.cc> | 2024-01-24 23:29:46 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2024-02-02 18:26:14 +0100 |
commit | 30a7f11234a81bd2389c7e7224769b1fdd192239 (patch) | |
tree | 7b4a1674937105e49e531f06e49b7309596759a9 /libxtables | |
parent | 285406b1d22e3ed0aec30ea0a534ea76211156a9 (diff) |
libxtables: xtoptions: Assert ranges are monotonic increasing
Extensions commonly require the upper range value to be larger or equal
to the lower one. Performing this check in the parser is easier and
covers all extensions at once.
One notable exception is NFQUEUE which requires strict monotonicity.
Hence leave its checks in place.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'libxtables')
-rw-r--r-- | libxtables/xtoptions.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c index f622f4c6..cecf7d35 100644 --- a/libxtables/xtoptions.c +++ b/libxtables/xtoptions.c @@ -291,8 +291,8 @@ static void xtopt_parse_mint(struct xt_option_call *cb) size_t esize = xtopt_esize_by_type(entry->type); const uintmax_t lmax = xtopt_max_by_type(entry->type); void *put = XTOPT_MKPTR(cb); + uintmax_t value, lmin = 0; unsigned int maxiter; - uintmax_t value; char *end = ""; char sep = ':'; @@ -314,16 +314,17 @@ static void xtopt_parse_mint(struct xt_option_call *cb) end = (char *)arg; value = (cb->nvals == 1) ? lmax : 0; } else { - if (!xtables_strtoul(arg, &end, &value, 0, lmax)) + if (!xtables_strtoul(arg, &end, &value, lmin, lmax)) xt_params->exit_err(PARAMETER_PROBLEM, "%s: bad value for option \"--%s\" near " - "\"%s\", or out of range (0-%ju).\n", - cb->ext_name, entry->name, arg, lmax); + "\"%s\", or out of range (%ju-%ju).\n", + cb->ext_name, entry->name, arg, lmin, lmax); if (*end != '\0' && *end != sep) xt_params->exit_err(PARAMETER_PROBLEM, "%s: Argument to \"--%s\" has " "unexpected characters near \"%s\".\n", cb->ext_name, entry->name, end); + lmin = value; } xtopt_mint_value_to_cb(cb, value); ++cb->nvals; |