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();
29  MpmTableSetup();
30  SpmTableSetup();
32  SigTableInit();
33  AppLayerSetup();
34  SigTableSetup();
35  }
36  if (cnt++ == 1024) {
38  de_ctx = NULL;
39  cnt = 0;
40  }
41  if (de_ctx == NULL) {
43  BUG_ON(de_ctx == NULL);
44  de_ctx->flags |= DE_QUIET;
45  de_ctx->rule_file = (char *)"fuzzer";
46  }
47 
48  char * buffer = malloc(size+1);
49  if (buffer) {
50  memcpy(buffer, data, size);
51  //null terminate string
52  buffer[size] = 0;
53  Signature *s = SigInit(de_ctx, buffer);
54  free(buffer);
55  if (s && s->next) {
56  SigFree(de_ctx, s->next);
57  s->next = NULL;
58  }
59  SigFree(de_ctx, s);
60  }
61 
62  return 0;
63 }
detect-engine.h
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:40
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:1661
DetectEngineCtx_::rule_file
char * rule_file
Definition: detect.h:949
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:504
SCRunmodeSet
void SCRunmodeSet(int run_mode)
Set the current run mode.
Definition: suricata.c:269
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:854
SigTableInit
void SigTableInit(void)
Definition: detect-engine-register.c:492
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2625
DE_QUIET
#define DE_QUIET
Definition: detect.h:325
GlobalsInitPreConfig
void GlobalsInitPreConfig(void)
Definition: suricata.c:362
Signature_::next
struct Signature_ * next
Definition: detect.h:686
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:249
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:2392
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:309
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:614
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2586
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:856
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2855
app-layer.h