From: Victor Julien Date: Tue, 16 Jan 2024 15:40:25 +0000 (+0100) Subject: mpm/ac: add endswith test X-Git-Tag: suricata-8.0.0-beta1~1645 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d47bfbb14dda9b737273e30cdd2a0dfecebc0bd8;p=thirdparty%2Fsuricata.git mpm/ac: add endswith test --- diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 891113ee83..270250c6fd 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -2118,6 +2118,35 @@ end: return result; } +/** \test endswith logic */ +static int SCACTest30(void) +{ + MpmCtx mpm_ctx; + MpmThreadCtx mpm_thread_ctx; + PrefilterRuleStore pmq; + + memset(&mpm_ctx, 0, sizeof(MpmCtx)); + memset(&mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); + MpmInitCtx(&mpm_ctx, MPM_AC); + + /* 0 match */ + MpmAddPatternCS(&mpm_ctx, (uint8_t *)"xyz", 3, 0, 0, 0, 0, MPM_PATTERN_FLAG_ENDSWITH); + PmqSetup(&pmq); + + SCACPreparePatterns(&mpm_ctx); + + const char *buf1 = "abcdefghijklmnopqrstuvwxyz"; + uint32_t cnt = SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf1, strlen(buf1)); + FAIL_IF_NOT(cnt == 1); + const char *buf2 = "xyzxyzxyzxyzxyzxyzxyza"; + cnt = SCACSearch(&mpm_ctx, &mpm_thread_ctx, &pmq, (uint8_t *)buf2, strlen(buf2)); + FAIL_IF_NOT(cnt == 0); + + SCACDestroyCtx(&mpm_ctx); + PmqFree(&pmq); + PASS; +} + void SCACRegisterTests(void) { UtRegisterTest("SCACTest01", SCACTest01); @@ -2149,5 +2178,6 @@ void SCACRegisterTests(void) UtRegisterTest("SCACTest27", SCACTest27); UtRegisterTest("SCACTest28", SCACTest28); UtRegisterTest("SCACTest29", SCACTest29); + UtRegisterTest("SCACTest30", SCACTest30); } #endif /* UNITTESTS */