summaryrefslogtreecommitdiffstats
path: root/libxtables
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2024-01-26 01:50:22 +0100
committerPhil Sutter <phil@nwl.cc>2024-02-02 18:26:14 +0100
commita392cf0e9b11b01352d02e81fbd5ad4da49bce94 (patch)
treefca7a2bfb9018dcc42a9a613d725fd318c65d194 /libxtables
parenta86eb41ef2987a9f99cb2ef644fbe2a2096d58b2 (diff)
libxtables: xtoptions: Respect min/max values when completing ranges
If an extension defines a minimum/maximum valid value for an option's range argument, treat this as the lower/upper boundary to use when completing (half) open ranges. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'libxtables')
-rw-r--r--libxtables/xtoptions.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c
index 0a995a63..774d0ee6 100644
--- a/libxtables/xtoptions.c
+++ b/libxtables/xtoptions.c
@@ -289,13 +289,16 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
const struct xt_option_entry *entry = cb->entry;
const char *arg;
size_t esize = xtopt_esize_by_type(entry->type);
- const uintmax_t lmax = xtopt_max_by_type(entry->type);
+ uintmax_t lmax = xtopt_max_by_type(entry->type);
+ uintmax_t value, lmin = entry->min;
void *put = XTOPT_MKPTR(cb);
- uintmax_t value, lmin = 0;
unsigned int maxiter;
char *end = "";
char sep = ':';
+ if (entry->max && entry->max < lmax)
+ lmax = entry->max;
+
maxiter = entry->size / esize;
if (maxiter == 0)
maxiter = ARRAY_SIZE(cb->val.u32_range);
@@ -312,7 +315,7 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
if (*arg == '\0' || *arg == sep) {
/* Default range components when field not spec'd. */
end = (char *)arg;
- value = (cb->nvals == 1) ? lmax : 0;
+ value = (cb->nvals == 1) ? lmax : lmin;
} else {
if (!xtables_strtoul(arg, &end, &value, lmin, lmax))
xt_params->exit_err(PARAMETER_PROBLEM,