From 935ea745f5e38b49713ae77d86b57ce7260917a4 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 1 Mar 2022 12:44:01 +0100 Subject: [PATCH] detect/iponly: add tests for 5168 --- src/detect-engine-iponly.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/detect-engine-iponly.c b/src/detect-engine-iponly.c index ca77b67692..d0647f09d6 100644 --- a/src/detect-engine-iponly.c +++ b/src/detect-engine-iponly.c @@ -2419,6 +2419,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) @@ -2461,6 +2488,9 @@ void IPOnlyRegisterTests(void) UtRegisterTest("IPOnlyTestBug5066v3", IPOnlyTestBug5066v3); UtRegisterTest("IPOnlyTestBug5066v4", IPOnlyTestBug5066v4); UtRegisterTest("IPOnlyTestBug5066v5", IPOnlyTestBug5066v5); + + UtRegisterTest("IPOnlyTestBug5168v1", IPOnlyTestBug5168v1); + UtRegisterTest("IPOnlyTestBug5168v2", IPOnlyTestBug5168v2); #endif return; -- 2.47.2