From: Philippe Antoine Date: Sat, 2 May 2020 13:55:23 +0000 (+0200) Subject: signature: fix linked list for bidirectional signatures X-Git-Tag: suricata-5.0.4~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6db4a37df68ea2051a04c39eac1293ca184ef3a;p=thirdparty%2Fsuricata.git signature: fix linked list for bidirectional signatures 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) --- diff --git a/src/detect-parse.c b/src/detect-parse.c index 3ea024ad36..f559f826b5 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -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) {