]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
signature: fix linked list for bidirectional signatures
authorPhilippe Antoine <pantoine@oisf.net>
Sat, 2 May 2020 13:55:23 +0000 (15:55 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 25 Aug 2020 12:49:26 +0000 (14:49 +0200)
Bidirectional signatures are really two signatures with one id
This needs to be handled with care when changing a linked list

(cherry picked from commit 5ac8e41a130f7b17678be00a1a5510a85f7baa2e)

src/detect-parse.c

index 3ea024ad36a016ab449bf69ce2d3d53c6c9b2613..f559f826b54ac6e831ddfccb776561b2bb434cd5 100644 (file)
@@ -2239,11 +2239,23 @@ static inline int DetectEngineSignatureIsDuplicate(DetectEngineCtx *de_ctx,
         memset(&sw_temp, 0, sizeof(SigDuplWrapper));
         if (sw_dup->s->init_data->init_flags & SIG_FLAG_INIT_BIDIREC) {
             sw_temp.s = sw_dup->s->next->next;
-            sw_dup->s_prev->next = sw_dup->s->next->next;
+            /* If previous signature is bidirectional,
+             * it has 2 items in the linked list.
+             * So we need to change next->next instead of next
+             */
+            if (sw_dup->s_prev->init_data->init_flags & SIG_FLAG_INIT_BIDIREC) {
+                sw_dup->s_prev->next->next = sw_dup->s->next->next;
+            } else {
+                sw_dup->s_prev->next = sw_dup->s->next->next;
+            }
             SigFree(sw_dup->s->next);
         } else {
             sw_temp.s = sw_dup->s->next;
-            sw_dup->s_prev->next = sw_dup->s->next;
+            if (sw_dup->s_prev->init_data->init_flags & SIG_FLAG_INIT_BIDIREC) {
+                sw_dup->s_prev->next->next = sw_dup->s->next;
+            } else {
+                sw_dup->s_prev->next = sw_dup->s->next;
+            }
         }
         SigDuplWrapper *sw_next = NULL;
         if (sw_temp.s != NULL) {