]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/files: increment local_file_id even if buffer is NULL 13292/head
authorPhilippe Antoine <pantoine@oisf.net>
Wed, 21 May 2025 13:34:26 +0000 (15:34 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 21 May 2025 17:42:11 +0000 (19:42 +0200)
Ticket: 7579

Otherwise, we will keep on calling again and again GetDataCallback
with the same local_file_id, and we will always get a NULL
buffer even if the next local_file_id would return a non-NULL buffer.

src/detect-file-data.c
src/detect-filemagic.c
src/detect-filename.c

index 0bc6c31872e2d9613da10abebabd1a496c384278..54a3ca05114dfa27f9d6a09041c684d717592606 100644 (file)
@@ -506,8 +506,10 @@ uint8_t DetectEngineInspectFiledata(DetectEngineCtx *de_ctx, DetectEngineThreadC
     for (; file != NULL; file = file->next) {
         InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx, transforms, f, flags, file,
                 engine->sm_list, engine->sm_list_base, local_file_id, txv);
-        if (buffer == NULL)
+        if (buffer == NULL) {
+            local_file_id++;
             continue;
+        }
 
         bool eof = (file->state == FILE_STATE_CLOSED);
         uint8_t ciflags = eof ? DETECT_CI_FLAGS_END : 0;
@@ -555,8 +557,10 @@ static void PrefilterTxFiledata(DetectEngineThreadCtx *det_ctx, const void *pect
         for (File *file = ffc->head; file != NULL; file = file->next) {
             InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx, ctx->transforms, f, flags,
                     file, list_id, ctx->base_list_id, local_file_id, txv);
-            if (buffer == NULL)
+            if (buffer == NULL) {
+                local_file_id++;
                 continue;
+            }
             SCLogDebug("[%" PRIu64 "] buffer size %u", p->pcap_cnt, buffer->inspect_len);
 
             if (buffer->inspect_len >= mpm_ctx->minlen) {
index 2a33be7570209dd4234065ae4584b1256453606f..1d756bb4d7fe25af9b91559a757e6cca3c153665 100644 (file)
@@ -326,8 +326,10 @@ static uint8_t DetectEngineInspectFilemagic(DetectEngineCtx *de_ctx, DetectEngin
     for (File *file = ffc->head; file != NULL; file = file->next) {
         InspectionBuffer *buffer = FilemagicGetDataCallback(
                 det_ctx, transforms, f, flags, file, engine->sm_list, local_file_id);
-        if (buffer == NULL)
+        if (buffer == NULL) {
+            local_file_id++;
             continue;
+        }
 
         const bool match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd, NULL, f,
                 buffer->inspect, buffer->inspect_len, buffer->inspect_offset,
index 5a4321c198802e69b7f58475c813233116ad36f3..df67166c3224e35d32e64637836e52ab309e5da0 100644 (file)
@@ -263,8 +263,10 @@ static uint8_t DetectEngineInspectFilename(DetectEngineCtx *de_ctx, DetectEngine
     for (File *file = ffc->head; file != NULL; file = file->next) {
         InspectionBuffer *buffer = FilenameGetDataCallback(
                 det_ctx, transforms, f, flags, file, engine->sm_list, local_file_id);
-        if (buffer == NULL)
+        if (buffer == NULL) {
+            local_file_id++;
             continue;
+        }
 
         const bool match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd, NULL, f,
                 buffer->inspect, buffer->inspect_len, buffer->inspect_offset,