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 #include "app-layer.h"
14 
15 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
16 
17 static uint32_t cnt = 0;
19 
20 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
21 {
22  if (de_ctx == NULL) {
23  setenv("SC_LOG_OP_IFACE", "file", 0);
24  setenv("SC_LOG_FILE", "/dev/null", 0);
25  //global init
26  InitGlobal();
28  MpmTableSetup();
29  SpmTableSetup();
31  SigTableInit();
32  AppLayerSetup();
33  SigTableSetup();
34  }
35  if (cnt++ == 1024) {
37  de_ctx = NULL;
38  cnt = 0;
39  }
40  if (de_ctx == NULL) {
42  BUG_ON(de_ctx == NULL);
43  de_ctx->flags |= DE_QUIET;
44  de_ctx->rule_file = (char *)"fuzzer";
45  }
46 
47  char * buffer = malloc(size+1);
48  if (buffer) {
49  memcpy(buffer, data, size);
50  //null terminate string
51  buffer[size] = 0;
52  Signature *s = SigInit(de_ctx, buffer);
53  free(buffer);
54  if (s && s->next) {
55  SigFree(de_ctx, s->next);
56  s->next = NULL;
57  }
58  SigFree(de_ctx, s);
59  }
60 
61  return 0;
62 }
detect-engine.h
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:40
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:1655
DetectEngineCtx_::rule_file
char * rule_file
Definition: detect.h:938
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:502
SCRunmodeSet
void SCRunmodeSet(int run_mode)
Set the current run mode.
Definition: suricata.c:265
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:843
SigTableInit
void SigTableInit(void)
Definition: detect-engine-register.c:490
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2623
DE_QUIET
#define DE_QUIET
Definition: detect.h:323
Signature_::next
struct Signature_ * next
Definition: detect.h:675
AppLayerSetup
int AppLayerSetup(void)
Setup the app layer.
Definition: app-layer.c:1075
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:245
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:224
setenv
void setenv(const char *name, const char *value, int overwrite)
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
suricata-common.h
util-classification-config.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: fuzz_siginit.c:20
detect-parse.h
Signature_
Signature container.
Definition: detect.h:603
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2584
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:845
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2851
app-layer.h