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 ConfYamlLoadString
5  */
6 
7 
8 #include "suricata-common.h"
9 #include "suricata.h"
10 #include "rust.h"
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  initialized = 1;
26  }
27 
28  uint32_t events;
31  MimeStateSMTP *state = SCMimeSmtpStateInit(files, &sbcfg);
32  const uint8_t * buffer = data;
33  while (1) {
34  uint8_t * next = memchr(buffer, '\n', size);
35  if (next == NULL) {
36  if (SCMimeSmtpGetState(state) >= MimeSmtpBody)
37  (void)SCSmtpMimeParseLine(buffer, size, 0, &events, state);
38  break;
39  } else {
40  (void)SCSmtpMimeParseLine(buffer, next - buffer, 1, &events, state);
41  if (buffer + size < next + 1) {
42  break;
43  }
44  size -= next - buffer + 1;
45  buffer = next + 1;
46  }
47  }
48  /* Completed */
49  (void)SCSmtpMimeComplete(state);
50  /* De Init parser */
51  SCMimeSmtpStateFree(state);
52  FileContainerFree(files, &sbcfg);
53 
54  return 0;
55 }
FileContainer_
Definition: util-file.h:113
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:40
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
SCRunmodeSet
void SCRunmodeSet(int run_mode)
Set the current run mode.
Definition: suricata.c:265
rust.h
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:16
suricata.h
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2856