From: Victor Julien Date: Tue, 1 Mar 2022 11:44:01 +0000 (+0100) Subject: detect/iponly: add tests for 5168 X-Git-Tag: suricata-5.0.9~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0f3baf7b4703d9dd9bf62cbc06f15fcb30a9c3a;p=thirdparty%2Fsuricata.git detect/iponly: add tests for 5168 (cherry picked from commit 935ea745f5e38b49713ae77d86b57ce7260917a4) --- diff --git a/src/detect-engine-iponly.c b/src/detect-engine-iponly.c index 0b89cca3d4..8e297f6b73 100644 --- a/src/detect-engine-iponly.c +++ b/src/detect-engine-iponly.c @@ -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;