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 #include "nallocinc.c"
15 
16 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
17 
18 static uint32_t cnt = 0;
20 static int initialized = 0;
21 SC_ATOMIC_EXTERN(unsigned int, engine_stage);
22 
23 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
24 {
25  if (de_ctx == NULL) {
26  setenv("SC_LOG_OP_IFACE", "file", 0);
27  setenv("SC_LOG_FILE", "/dev/null", 0);
28  //global init
29  InitGlobal();
32  MpmTableSetup();
33  SpmTableSetup();
35  SigTableInit();
36  AppLayerSetup();
37  SigTableSetup();
38  if (initialized == 0) {
39  nalloc_init(NULL);
41  SC_ATOMIC_SET(engine_stage, SURICATA_RUNTIME);
42  initialized = 1;
43  }
44  }
45  if (cnt++ == 1024) {
47  de_ctx = NULL;
48  cnt = 0;
49  }
50  if (de_ctx == NULL) {
52  BUG_ON(de_ctx == NULL);
53  de_ctx->flags |= DE_QUIET;
54  de_ctx->rule_file = (char *)"fuzzer";
55  }
56 
57  char * buffer = malloc(size+1);
58  if (buffer) {
59  memcpy(buffer, data, size);
60  //null terminate string
61  buffer[size] = 0;
62  nalloc_start(data, size);
63  Signature *s = SigInit(de_ctx, buffer);
64  free(buffer);
65  if (s && s->next) {
66  SigFree(de_ctx, s->next);
67  s->next = NULL;
68  }
69  SigFree(de_ctx, s);
70  nalloc_end();
71  }
72 
73  return 0;
74 }
detect-engine.h
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:2064
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
SigTableSetup
void SigTableSetup(void)
Definition: detect-engine-register.c:550
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:933
SigTableInit
void SigTableInit(void)
Definition: detect-engine-register.c:538
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2634
DE_QUIET
#define DE_QUIET
Definition: detect.h:330
GlobalsInitPreConfig
void GlobalsInitPreConfig(void)
Definition: suricata.c:386
nallocinc.c
SCRunmodeSet
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition: suricata.c:288
Signature_::next
struct Signature_ * next
Definition: detect.h:750
AppLayerSetup
int AppLayerSetup(void)
Setup the app layer.
Definition: app-layer.c:1074
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:19
SURICATA_RUNTIME
@ SURICATA_RUNTIME
Definition: suricata.h:101
EngineModeSetIDS
void EngineModeSetIDS(void)
Definition: suricata.c:268
SpmTableSetup
void SpmTableSetup(void)
Definition: util-spm.c:122
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:41
util-reference-config.h
SC_ATOMIC_EXTERN
SC_ATOMIC_EXTERN(unsigned int, engine_stage)
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:3105
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:317
MpmTableSetup
void MpmTableSetup(void)
Definition: util-mpm.c:224
setenv
void setenv(const char *name, const char *value, int overwrite)
nalloc_init
#define nalloc_init(x)
Definition: nallocinc.c:49
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
DetectEngineCtx_::rule_file
const char * rule_file
Definition: detect.h:1025
suricata-common.h
nalloc_start
#define nalloc_start(x, y)
Definition: nallocinc.c:51
util-classification-config.h
nalloc_end
#define nalloc_end()
Definition: nallocinc.c:52
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: fuzz_siginit.c:23
detect-parse.h
Signature_
Signature container.
Definition: detect.h:668
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2595
nalloc_restrict_file_prefix
#define nalloc_restrict_file_prefix(x)
Definition: nallocinc.c:50
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:935
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2986
app-layer.h