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"
11 #include "detect-engine.h"
12 #include "detect-parse.h"
13 
14 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
15 
17 
18 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
19 {
20  if (de_ctx == NULL) {
21  setenv("SC_LOG_OP_IFACE", "file", 0);
22  setenv("SC_LOG_FILE", "/dev/null", 0);
23  //global init
24  InitGlobal();
26  MpmTableSetup();
27  SpmTableSetup();
28  SigTableSetup();
32  BUG_ON(de_ctx == NULL);
33  de_ctx->flags |= DE_QUIET;
34  de_ctx->rule_file = (char *)"fuzzer";
35  }
36 
37  char * buffer = malloc(size+1);
38  if (buffer) {
39  memcpy(buffer, data, size);
40  //null terminate string
41  buffer[size] = 0;
42  Signature *s = SigInit(de_ctx, buffer);
43  free(buffer);
44  if (s && s->next) {
45  SigFree(s->next);
46  s->next = NULL;
47  }
48  SigFree(s);
49  }
50 
51  return 0;
52 }
detect-engine.h
SCReferenceConfInit
void SCReferenceConfInit(void)
Definition: util-reference-config.c:56
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:39
DetectEngineCtx_::rule_file
char * rule_file
Definition: detect.h:865
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:399
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2023
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:761
SigFree
void SigFree(Signature *)
Definition: detect-parse.c:1377
DE_QUIET
#define DE_QUIET
Definition: detect.h:292
Signature_::next
struct Signature_ * next
Definition: detect.h:594
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:16
SpmTableSetup
void SpmTableSetup(void)
Definition: util-spm.c:117
util-reference-config.h
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:265
MpmTableSetup
void MpmTableSetup(void)
Definition: util-mpm.c:279
setenv
void setenv(const char *name, const char *value, int overwrite)
suricata-common.h
run_mode
int run_mode
Definition: suricata.c:201
util-classification-config.h
SCClassConfInit
void SCClassConfInit(void)
Definition: util-classification-config.c:63
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: fuzz_siginit.c:18
detect-parse.h
Signature_
Signature container.
Definition: detect.h:522
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:1985
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:762
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2640