]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/content: cleanup content setup/check code
authorVictor Julien <vjulien@oisf.net>
Tue, 21 Mar 2023 05:37:19 +0000 (06:37 +0100)
committerVictor Julien <vjulien@oisf.net>
Fri, 14 Apr 2023 08:43:31 +0000 (10:43 +0200)
Pass SigMatch pointer instead of a list id to SigParseRequiredContentSize.

src/detect-bsize.c
src/detect-content.c
src/detect-content.h
src/detect-dsize.c

index 6639742f8ee4ec69fc05fb68d0fed0c93a91af30..4c89abc3c6a8fcb166b0ab8218f93e92c28b839a 100644 (file)
@@ -64,7 +64,7 @@ bool DetectBsizeValidateContentCallback(Signature *s, int list)
     uint64_t needed;
     if (bsize >= 0) {
         int len, offset;
-        SigParseRequiredContentSize(s, bsize, list, &len, &offset);
+        SigParseRequiredContentSize(s, bsize, s->init_data->smlists[list], &len, &offset);
         SCLogDebug("bsize: %d; len: %d; offset: %d [%s]", bsize, len, offset, s->sig_str);
         needed = len;
         if (len > bsize) {
index 891eee523a24a56571c6a904759da15c4c8b036d..a66497d400e39087884eb86612d1cafcf61a1759 100644 (file)
@@ -412,13 +412,8 @@ void DetectContentFree(DetectEngineCtx *de_ctx, void *ptr)
  *  - Negated content values are checked but not accumulated for the required size.
  */
 void SigParseRequiredContentSize(
-        const Signature *s, const int max_size, int list, int *len, int *offset)
+        const Signature *s, const int max_size, const SigMatch *sm, int *len, int *offset)
 {
-    if (list > (int)s->init_data->smlists_array_size) {
-        return;
-    }
-
-    SigMatch *sm = s->init_data->smlists[list];
     int max_offset = 0, total_len = 0;
     bool first = true;
     for (; sm != NULL; sm = sm->next) {
index ae179ad076d4695be232663ab252cb7b06e5b3ef..d1f3d6fbc1b633e53ab181242695460b6e2e5e4f 100644 (file)
@@ -132,6 +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, int list, int *len, int *offset);
+        const Signature *s, const int max, const SigMatch *sm, int *len, int *offset);
 
 #endif /* __DETECT_CONTENT_H__ */
index 9d62457fc16fd2b2a14edfc065beeeff7816d352..4336e3546b9fa66334491cb7f819e06b72c4c290 100644 (file)
@@ -315,7 +315,8 @@ int SigParseMaxRequiredDsize(const Signature *s)
     }
 
     int total_length, offset;
-    SigParseRequiredContentSize(s, dsize, DETECT_SM_LIST_PMATCH, &total_length, &offset);
+    SigParseRequiredContentSize(
+            s, dsize, s->init_data->smlists[DETECT_SM_LIST_PMATCH], &total_length, &offset);
     SCLogDebug("dsize: %d  len: %d; offset: %d [%s]", dsize, total_length, offset, s->sig_str);
 
     if (total_length > dsize) {