]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: xtoptions: Respect min/max values when completing ranges
authorPhil Sutter <phil@nwl.cc>
Fri, 26 Jan 2024 00:50:22 +0000 (01:50 +0100)
committerPhil Sutter <phil@nwl.cc>
Fri, 2 Feb 2024 17:26:14 +0000 (18:26 +0100)
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>
extensions/libxt_NFQUEUE.t
libxtables/xtoptions.c

index 1adb8e40230992a747e9f19e77e75489469317ab..94050500d195bc503553642c5bd663b3e5762391 100644 (file)
@@ -9,9 +9,9 @@
 -j NFQUEUE --queue-balance 0:65536;;FAIL
 -j NFQUEUE --queue-balance -1:65535;;FAIL
 -j NFQUEUE --queue-balance 4;;FAIL
--j NFQUEUE --queue-balance :;;FAIL
+-j NFQUEUE --queue-balance :;-j NFQUEUE --queue-balance 0:65534;OK
 -j NFQUEUE --queue-balance :4;-j NFQUEUE --queue-balance 0:4;OK
--j NFQUEUE --queue-balance 4:;-j NFQUEUE --queue-balance 4:65535;OK
+-j NFQUEUE --queue-balance 4:;-j NFQUEUE --queue-balance 4:65534;OK
 -j NFQUEUE --queue-balance 3:4;=;OK
 -j NFQUEUE --queue-balance 4:4;;FAIL
 -j NFQUEUE --queue-balance 4:3;;FAIL
index 0a995a63a2a88a2060a898b5f231a1c64a45b589..774d0ee655ba73754a2f15a297c4410e34db315a 100644 (file)
@@ -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,