]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/address: validate netmasks
authorVictor Julien <vjulien@oisf.net>
Tue, 1 Mar 2022 11:41:04 +0000 (12:41 +0100)
committerShivani Bhardwaj <shivanib134@gmail.com>
Fri, 4 Mar 2022 05:38:17 +0000 (11:08 +0530)
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 259bd8aa92c7bc8ca8c74b3f429f321935493828)

src/detect-engine-address.c

index 3b47b4325ae53b8d2b8ae31e135d885525397c64..c529ef66b913d53aededb71d9cbfd21df1a439f0 100644 (file)
@@ -452,6 +452,16 @@ static int DetectAddressParseString(DetectAddress *dd, const char *str)
                     goto error;
 
                 netmask = in.s_addr;
+
+                /* validate netmask */
+                int cidr = CIDRFromMask(netmask);
+                if (cidr < 0) {
+                    SCLogError(SC_ERR_INVALID_SIGNATURE,
+                            "netmask \"%s\" is not usable. Only netmasks that are compatible with "
+                            "CIDR notation are supported. See #5168.",
+                            mask);
+                    goto error;
+                }
             }
 
             r = inet_pton(AF_INET, ip, &in);