suricata
fuzz_mimedecparseline.c
Go to the documentation of this file.
1 /**
2  * @file
3  * @author Philippe Antoine <contact@catenacyber.fr>
4  * fuzz target for SCConfYamlLoadString
5  */
6 
7 #include "suricata-common.h"
8 #include "suricata.h"
9 #include "rust.h"
10 #include "nallocinc.c"
11 
12 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
13 
14 static int initialized = 0;
15 
16 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17 {
18  if (initialized == 0) {
19  //Redirects logs to /dev/null
20  setenv("SC_LOG_OP_IFACE", "file", 0);
21  setenv("SC_LOG_FILE", "/dev/null", 0);
22  //global init
23  InitGlobal();
25  nalloc_init(NULL);
26  // do not restrict nalloc
27  initialized = 1;
28  }
29 
30  uint32_t events;
33  MimeStateSMTP *state = SCMimeSmtpStateInit(files, &sbcfg);
34  const uint8_t * buffer = data;
35  nalloc_start(data, size);
36  while (1) {
37  uint8_t * next = memchr(buffer, '\n', size);
38  if (next == NULL) {
39  if (SCMimeSmtpGetState(state) >= MimeSmtpBody)
40  (void)SCSmtpMimeParseLine(buffer, (uint32_t)size, 0, &events, state);
41  break;
42  } else {
43  (void)SCSmtpMimeParseLine(buffer, (uint32_t)(next - buffer), 1, &events, state);
44  if (buffer + size < next + 1) {
45  break;
46  }
47  size -= next - buffer + 1;
48  buffer = next + 1;
49  }
50  }
51  /* Completed */
52  (void)SCSmtpMimeComplete(state);
53  /* De Init parser */
54  SCMimeSmtpStateFree(state);
55  FileContainerFree(files, &sbcfg);
56  nalloc_end();
57 
58  return 0;
59 }
FileContainer_
Definition: util-file.h:37
FileContainerAlloc
FileContainer * FileContainerAlloc(void)
allocate a FileContainer
Definition: util-file.c:479
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
STREAMING_BUFFER_CONFIG_INITIALIZER
#define STREAMING_BUFFER_CONFIG_INITIALIZER
Definition: util-streaming-buffer.h:74
FileContainerFree
void FileContainerFree(FileContainer *ffc, const StreamingBufferConfig *cfg)
Free a FileContainer.
Definition: util-file.c:515
rust.h
nallocinc.c
SCRunmodeSet
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition: suricata.c:288
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:41
setenv
void setenv(const char *name, const char *value, int overwrite)
nalloc_init
#define nalloc_init(x)
Definition: nallocinc.c:49
suricata-common.h
nalloc_start
#define nalloc_start(x, y)
Definition: nallocinc.c:51
nalloc_end
#define nalloc_end()
Definition: nallocinc.c:52
StreamingBufferConfig_
Definition: util-streaming-buffer.h:65
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: fuzz_mimedecparseline.c:16
suricata.h
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2998