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
15int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
16
17static uint32_t cnt = 0;
19
20int 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();
35 }
36 if (cnt++ == 1024) {
38 de_ctx = NULL;
39 cnt = 0;
40 }
41 if (de_ctx == NULL) {
43 BUG_ON(de_ctx == NULL);
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}
int AppLayerSetup(void)
Setup the app layer.
Definition app-layer.c:1078
void SigTableSetup(void)
void SigTableInit(void)
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
void SigFree(DetectEngineCtx *, Signature *)
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
#define DE_QUIET
Definition detect.h:330
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
DetectEngineCtx * de_ctx
@ RUNMODE_UNITTEST
Definition runmodes.h:41
main detection engine ctx
Definition detect.h:932
const char * rule_file
Definition detect.h:1024
uint8_t flags
Definition detect.h:934
Signature container.
Definition detect.h:668
struct Signature_ * next
Definition detect.h:750
#define BUG_ON(x)
int InitGlobal(void)
Global initialization common to all runmodes.
Definition suricata.c:2965
void EngineModeSetIDS(void)
Definition suricata.c:264
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition suricata.c:284
void GlobalsInitPreConfig(void)
Definition suricata.c:382
void MpmTableSetup(void)
Definition util-mpm.c:224
void SpmTableSetup(void)
Definition util-spm.c:122
void setenv(const char *name, const char *value, int overwrite)