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 
11 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
12 
13 static int initialized = 0;
14 
15 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
16 {
17  if (initialized == 0) {
18  //Redirects logs to /dev/null
19  setenv("SC_LOG_OP_IFACE", "file", 0);
20  setenv("SC_LOG_FILE", "/dev/null", 0);
21  //global init
22  InitGlobal();
24  initialized = 1;
25  }
26 
27  uint32_t events;
30  MimeStateSMTP *state = SCMimeSmtpStateInit(files, &sbcfg);
31  const uint8_t * buffer = data;
32  while (1) {
33  uint8_t * next = memchr(buffer, '\n', size);
34  if (next == NULL) {
35  if (SCMimeSmtpGetState(state) >= MimeSmtpBody)
36  (void)SCSmtpMimeParseLine(buffer, size, 0, &events, state);
37  break;
38  } else {
39  (void)SCSmtpMimeParseLine(buffer, next - buffer, 1, &events, state);
40  if (buffer + size < next + 1) {
41  break;
42  }
43  size -= next - buffer + 1;
44  buffer = next + 1;
45  }
46  }
47  /* Completed */
48  (void)SCSmtpMimeComplete(state);
49  /* De Init parser */
50  SCMimeSmtpStateFree(state);
51  FileContainerFree(files, &sbcfg);
52 
53  return 0;
54 }
FileContainer_
Definition: util-file.h:113
FileContainerAlloc
FileContainer * FileContainerAlloc(void)
allocate a FileContainer
Definition: util-file.c:497
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:533
rust.h
SCRunmodeSet
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition: suricata.c:271
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:41
setenv
void setenv(const char *name, const char *value, int overwrite)
suricata-common.h
StreamingBufferConfig_
Definition: util-streaming-buffer.h:65
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: fuzz_mimedecparseline.c:15
suricata.h
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2875