]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: xtoptions: Fix for non-CIDR-compatible hostmasks
authorPhil Sutter <phil@nwl.cc>
Tue, 28 Nov 2023 19:21:49 +0000 (20:21 +0100)
committerPhil Sutter <phil@nwl.cc>
Wed, 29 Nov 2023 01:33:06 +0000 (02:33 +0100)
In order to parse the mask, xtopt_parse_hostmask() calls
xtopt_parse_plenmask() thereby limiting netmask support to prefix
lengths (alternatively specified in IP address notation).

In order to lift this impractical restriction, make
xtopt_parse_plenmask() aware of the fact that xtopt_parse_plen() may
fall back to xtopt_parse_mask() which correctly initializes val.hmask
itself and indicates non-CIDR-compatible masks by setting val.hlen to
-1.

So in order to support these odd masks, it is sufficient for
xtopt_parse_plenmask() to skip its mask building from val.hlen value and
take whatever val.hmask contains.

Fixes: 66266abd17adc ("libxtables: XTTYPE_HOSTMASK support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
libxtables/xtoptions.c

index 64d740e334b745a4a74392522b4322c57368d4db..5964a9bfb57fef34b1e899e47bc2de744280eda4 100644 (file)
@@ -691,6 +691,10 @@ static void xtopt_parse_plenmask(struct xt_option_call *cb)
 
        xtopt_parse_plen(cb);
 
+       /* may not be convertible to CIDR notation */
+       if (cb->val.hlen == (uint8_t)-1)
+               goto out_put;
+
        memset(mask, 0xFF, sizeof(union nf_inet_addr));
        /* This shifting is AF-independent. */
        if (cb->val.hlen == 0) {
@@ -711,6 +715,7 @@ static void xtopt_parse_plenmask(struct xt_option_call *cb)
        mask[1] = htonl(mask[1]);
        mask[2] = htonl(mask[2]);
        mask[3] = htonl(mask[3]);
+out_put:
        if (entry->flags & XTOPT_PUT)
                memcpy(XTOPT_MKPTR(cb), mask, sizeof(union nf_inet_addr));
 }