suricata
fuzz_siginit.c
Go to the documentation of this file.
1
/**
2
* @file
3
* @author Philippe Antoine <contact@catenacyber.fr>
4
* fuzz target for SigInit
5
*/
6
7
8
#include "
suricata-common.h
"
9
#include "
util-reference-config.h
"
10
#include "
util-classification-config.h
"
11
#include "
detect-engine.h
"
12
#include "
detect-parse.h
"
13
14
int
LLVMFuzzerTestOneInput
(
const
uint8_t *data,
size_t
size);
15
16
static
uint32_t
cnt
= 0;
17
DetectEngineCtx
*
de_ctx
= NULL;
18
19
int
LLVMFuzzerTestOneInput
(
const
uint8_t *data,
size_t
size)
20
{
21
if
(
de_ctx
== NULL) {
22
setenv
(
"SC_LOG_OP_IFACE"
,
"file"
, 0);
23
setenv
(
"SC_LOG_FILE"
,
"/dev/null"
, 0);
24
//global init
25
InitGlobal
();
26
run_mode
=
RUNMODE_UNITTEST
;
27
MpmTableSetup
();
28
SpmTableSetup
();
29
EngineModeSetIDS
();
30
SigTableSetup
();
31
}
32
if
(
cnt
++ == 1024) {
33
DetectEngineCtxFree
(
de_ctx
);
34
de_ctx
= NULL;
35
cnt
= 0;
36
}
37
if
(
de_ctx
== NULL) {
38
de_ctx
=
DetectEngineCtxInit
();
39
BUG_ON
(
de_ctx
== NULL);
40
de_ctx
->
flags
|=
DE_QUIET
;
41
de_ctx
->
rule_file
= (
char
*)
"fuzzer"
;
42
}
43
44
char
* buffer = malloc(size+1);
45
if
(buffer) {
46
memcpy(buffer, data, size);
47
//null terminate string
48
buffer[size] = 0;
49
Signature
*s =
SigInit
(
de_ctx
, buffer);
50
free(buffer);
51
if
(s && s->
next
) {
52
SigFree
(
de_ctx
, s->
next
);
53
s->
next
= NULL;
54
}
55
SigFree
(
de_ctx
, s);
56
}
57
58
return
0;
59
}
detect-engine.h
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition:
runmodes.h:41
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition:
detect-parse.c:1644
DetectEngineCtx_::rule_file
char * rule_file
Definition:
detect.h:926
SigTableSetup
void SigTableSetup(void)
Definition:
detect-engine-register.c:471
DetectEngineCtx_
main detection engine ctx
Definition:
detect.h:836
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition:
detect-engine.c:2580
DE_QUIET
#define DE_QUIET
Definition:
detect.h:321
Signature_::next
struct Signature_ * next
Definition:
detect.h:665
de_ctx
DetectEngineCtx * de_ctx
Definition:
fuzz_siginit.c:17
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition:
suricata.c:246
SpmTableSetup
void SpmTableSetup(void)
Definition:
util-spm.c:122
util-reference-config.h
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition:
detect-parse.c:2314
BUG_ON
#define BUG_ON(x)
Definition:
suricata-common.h:300
MpmTableSetup
void MpmTableSetup(void)
Definition:
util-mpm.c:225
setenv
void setenv(const char *name, const char *value, int overwrite)
cnt
uint32_t cnt
Definition:
tmqh-packetpool.h:7
suricata-common.h
run_mode
int run_mode
Definition:
suricata.c:176
util-classification-config.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition:
fuzz_siginit.c:19
detect-parse.h
Signature_
Signature container.
Definition:
detect.h:593
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition:
detect-engine.c:2541
DetectEngineCtx_::flags
uint8_t flags
Definition:
detect.h:838
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition:
suricata.c:2849
src
tests
fuzz
fuzz_siginit.c
Generated on Mon Mar 18 2024 23:30:44 for suricata by
1.8.18