]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/iponly: validate netmask
authorVictor Julien <vjulien@oisf.net>
Tue, 1 Mar 2022 11:42:49 +0000 (12:42 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 21 Mar 2022 08:17:32 +0000 (09:17 +0100)
Only accept netmask in dotted quad notation if they can be turned
into a CIDR.

According to rfc 4632, CIDR (compat) netmasks are all that should be
used.

Bug: #5168.
(cherry picked from commit 79b7b7a0ddfdcd7664ca328a41d24fbca75e3e54)

src/detect-engine-iponly.c

index 50198acdce66c6953a0ed87a10679097e89fc367..0b89cca3d448168315c4d1334f8ace8b5bd43e43 100644 (file)
@@ -227,16 +227,11 @@ static int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem **pdd, const char *str)
                 if (r <= 0)
                     goto error;
 
-                netmask = in.s_addr;
-                if (netmask != 0) {
-                    uint32_t m = netmask;
-                    /* Extract cidr netmask */
-                    while ((0x01 & m) == 0) {
-                        dd->netmask++;
-                        m = m >> 1;
-                    }
-                    dd->netmask = 32 - dd->netmask;
-                }
+                int cidr = CIDRFromMask(in.s_addr);
+                if (cidr < 0)
+                    goto error;
+
+                dd->netmask = (uint8_t)cidr;
             }
 
             r = inet_pton(AF_INET, ip, &in);