]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/content: cleanup nocase conversion
authorVictor Julien <vjulien@oisf.net>
Fri, 4 Aug 2023 12:18:20 +0000 (14:18 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 8 Aug 2023 17:02:58 +0000 (19:02 +0200)
(cherry picked from commit ef936acdba0cda1da09ff4b7ea35281bd8f18429)

src/detect-content.c
src/detect-content.h
src/detect-nocase.c

index d0c71755fb851958337390f4ec320e2750ff0998..0391ba9e8f46ed44e5747f3ef72e701ba13dc6ca 100644 (file)
@@ -658,6 +658,30 @@ void DetectContentPropagateLimits(Signature *s)
 #undef VALIDATE
 }
 
+int DetectContentConvertToNocase(DetectEngineCtx *de_ctx, DetectContentData *cd)
+{
+    if (cd->flags & DETECT_CONTENT_NOCASE) {
+        SCLogError(SC_ERR_INVALID_SIGNATURE,
+                "can't use multiple nocase modifiers with the same content");
+        return -1;
+    }
+
+    /* for consistency in later use (e.g. by MPM construction and hashing),
+     * coerce the content string to lower-case. */
+    for (uint8_t *c = cd->content; c < cd->content + cd->content_len; c++) {
+        *c = u8_tolower(*c);
+    }
+
+    cd->flags |= DETECT_CONTENT_NOCASE;
+    /* Recreate the context with nocase chars */
+    SpmDestroyCtx(cd->spm_ctx);
+    cd->spm_ctx = SpmInitCtx(cd->content, cd->content_len, 1, de_ctx->spm_global_thread_ctx);
+    if (cd->spm_ctx == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
 #ifdef UNITTESTS /* UNITTESTS */
 
 static bool TestLastContent(const Signature *s, uint16_t o, uint16_t d)
index 83589fd6eaa267e58e033d54dee693c57ad73920..ef87d7f7f432df8e3de699a51f74a9a046798cb6 100644 (file)
@@ -123,4 +123,6 @@ void DetectContentFree(DetectEngineCtx *, void *);
 bool DetectContentPMATCHValidateCallback(const Signature *s);
 void DetectContentPropagateLimits(Signature *s);
 
+int DetectContentConvertToNocase(DetectEngineCtx *de_ctx, DetectContentData *cd);
+
 #endif /* __DETECT_CONTENT_H__ */
index 60f7330597aaf17ca41b8e95a57f0418d439f5e1..65d6b83e823ba9902a3adeceb52dae7e1262a648 100644 (file)
@@ -73,30 +73,8 @@ static int DetectNocaseSetup (DetectEngineCtx *de_ctx, Signature *s, const char
         goto end;
     }
 
-    /* verify other conditions. */
-    DetectContentData *cd = (DetectContentData *)pm->ctx;;
-
-    if (cd->flags & DETECT_CONTENT_NOCASE) {
-        SCLogError(SC_ERR_INVALID_SIGNATURE, "can't use multiple nocase modifiers with the same content");
-        goto end;
-    }
-
-    /* for consistency in later use (e.g. by MPM construction and hashing),
-     * coerce the content string to lower-case. */
-    for (uint8_t *c = cd->content; c < cd->content + cd->content_len; c++) {
-        *c = u8_tolower(*c);
-    }
-
-    cd->flags |= DETECT_CONTENT_NOCASE;
-    /* Recreate the context with nocase chars */
-    SpmDestroyCtx(cd->spm_ctx);
-    cd->spm_ctx = SpmInitCtx(cd->content, cd->content_len, 1,
-                             de_ctx->spm_global_thread_ctx);
-    if (cd->spm_ctx == NULL) {
-        goto end;
-    }
-
-    ret = 0;
+    DetectContentData *cd = (DetectContentData *)pm->ctx;
+    ret = DetectContentConvertToNocase(de_ctx, cd);
  end:
     SCReturnInt(ret);
 }