]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/iponly: add tests for 5168 7153/head
authorVictor Julien <vjulien@oisf.net>
Tue, 1 Mar 2022 11:44:01 +0000 (12:44 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 21 Mar 2022 08:17:32 +0000 (09:17 +0100)
(cherry picked from commit 935ea745f5e38b49713ae77d86b57ce7260917a4)

src/detect-engine-iponly.c

index 0b89cca3d448168315c4d1334f8ace8b5bd43e43..8e297f6b73e0edabf90cd1956d21ea2a04a4d9e1 100644 (file)
@@ -2415,6 +2415,33 @@ static int IPOnlyTestBug5066v5(void)
     PASS;
 }
 
+static int IPOnlyTestBug5168v1(void)
+{
+    IPOnlyCIDRItem *x = IPOnlyCIDRItemNew();
+    FAIL_IF_NULL(x);
+
+    FAIL_IF(IPOnlyCIDRItemParseSingle(&x, "1.2.3.64/0.0.0.0") != 0);
+
+    char ip[16];
+    PrintInet(AF_INET, (const void *)&x->ip[0], ip, sizeof(ip));
+    SCLogDebug("ip %s netmask %d", ip, x->netmask);
+
+    FAIL_IF_NOT(strcmp(ip, "0.0.0.0") == 0);
+    FAIL_IF_NOT(x->netmask == 0);
+
+    IPOnlyCIDRListFree(x);
+    PASS;
+}
+
+static int IPOnlyTestBug5168v2(void)
+{
+    IPOnlyCIDRItem *x = IPOnlyCIDRItemNew();
+    FAIL_IF_NULL(x);
+    FAIL_IF(IPOnlyCIDRItemParseSingle(&x, "0.0.0.5/0.0.0.5") != -1);
+    IPOnlyCIDRListFree(x);
+    PASS;
+}
+
 #endif /* UNITTESTS */
 
 void IPOnlyRegisterTests(void)
@@ -2457,6 +2484,9 @@ void IPOnlyRegisterTests(void)
     UtRegisterTest("IPOnlyTestBug5066v3", IPOnlyTestBug5066v3);
     UtRegisterTest("IPOnlyTestBug5066v4", IPOnlyTestBug5066v4);
     UtRegisterTest("IPOnlyTestBug5066v5", IPOnlyTestBug5066v5);
+
+    UtRegisterTest("IPOnlyTestBug5168v1", IPOnlyTestBug5168v1);
+    UtRegisterTest("IPOnlyTestBug5168v2", IPOnlyTestBug5168v2);
 #endif
 
     return;