]> 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>
Mon, 7 Aug 2023 18:40:59 +0000 (20:40 +0200)
src/detect-content.c
src/detect-content.h
src/detect-nocase.c

index 6026cf2956cab06474efa221e77137a176162171..5bbe9e9b3cae27623da66e788bb46bfb2e7ed76b 100644 (file)
@@ -754,6 +754,29 @@ void DetectContentPatternPrettyPrint(const DetectContentData *cd, char *str, siz
     }
 }
 
+int DetectContentConvertToNocase(DetectEngineCtx *de_ctx, DetectContentData *cd)
+{
+    if (cd->flags & DETECT_CONTENT_NOCASE) {
+        SCLogError("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 */
 #include "detect-engine-alert.h"
 #include "packet.h"
index cf56118b05206df130ed96a6aae5fc030fddf8f8..bc47562a96f8a78b4de488f986ddc992a5452dd3 100644 (file)
@@ -132,5 +132,6 @@ void DetectContentPropagateLimits(Signature *s);
 void DetectContentPatternPrettyPrint(const DetectContentData *cd, char *str, size_t str_len);
 void SigParseRequiredContentSize(
         const Signature *s, const int max, const SigMatch *sm, int *len, int *offset);
+int DetectContentConvertToNocase(DetectEngineCtx *de_ctx, DetectContentData *cd);
 
 #endif /* __DETECT_CONTENT_H__ */
index 34e60507e2d53497bd6612c4ade8c377cb9ce86c..deed7b2513da218a19e51893fb50509d28ddd32d 100644 (file)
@@ -74,30 +74,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("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;
+    ret = DetectContentConvertToNocase(de_ctx, cd);
  end:
     SCReturnInt(ret);
 }