suricata
detect-parse.c
Go to the documentation of this file.
1 
2 /* Copyright (C) 2007-2019 Open Information Security Foundation
3  *
4  * You can copy, redistribute or modify this Program under the terms of
5  * the GNU General Public License version 2 as published by the Free
6  * Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * version 2 along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA.
17  */
18 
19 #include "../detect-parse.h"
20 #include "../util-unittest.h"
21 
22 /**
23  * \test DetectParseTest01 is a regression test against a memory leak
24  * in the case of multiple signatures with different revisions
25  * Leak happened in function DetectEngineSignatureIsDuplicate
26  */
27 
28 static int DetectParseTest01 (void)
29 {
31  FAIL_IF(DetectEngineAppendSig(de_ctx, "alert http any any -> any any (msg:\"sid 1 version 0\"; content:\"dummy1\"; sid:1;)") == NULL);
32  DetectEngineAppendSig(de_ctx, "alert http any any -> any any (msg:\"sid 2 version 0\"; content:\"dummy2\"; sid:2;)");
33  DetectEngineAppendSig(de_ctx, "alert http any any -> any any (msg:\"sid 1 version 1\"; content:\"dummy1.1\"; sid:1; rev:1;)");
34  DetectEngineAppendSig(de_ctx, "alert http any any -> any any (msg:\"sid 2 version 2\"; content:\"dummy2.1\"; sid:2; rev:1;)");
35  FAIL_IF(de_ctx->sig_list->next == NULL);
36  DetectEngineCtxFree(de_ctx);
37 
38  PASS;
39 }
40 
41 
42 /**
43  * \brief this function registers unit tests for DetectParse
44  */
46 {
47  UtRegisterTest("DetectParseTest01", DetectParseTest01);
48 }
Signature * DetectEngineAppendSig(DetectEngineCtx *de_ctx, const char *sigstr)
Parse and append a Signature into the Detection Engine Context signature list.
#define PASS
Pass the test.
Signature * sig_list
Definition: detect.h:762
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:71
main detection engine ctx
Definition: detect.h:756
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
struct Signature_ * next
Definition: detect.h:589
void DetectParseRegisterTests(void)
this function registers unit tests for DetectParse
Definition: detect-parse.c:45
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
DetectEngineCtx * DetectEngineCtxInit(void)