]> 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>
Mon, 6 Jul 2020 17:06:21 +0000 (19:06 +0200)
Bidirectional signatures are really two signatures with one id
This needs to be handled with care when changing a linked list

src/detect-parse.c

index 673a8196ef30775d4047d6042480597b0223fa04..d6956b62637a7d35d24f9cc326197f8505cc37fc 100644 (file)
@@ -2263,11 +2263,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(de_ctx, 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) {