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
11int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
12
13static int initialized = 0;
14
15int 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, (uint32_t)size, 0, &events, state);
37 break;
38 } else {
39 (void)SCSmtpMimeParseLine(buffer, (uint32_t)(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}
struct HtpBodyChunk_ * next
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
@ RUNMODE_UNITTEST
Definition runmodes.h:41
int InitGlobal(void)
Global initialization common to all runmodes.
Definition suricata.c:2965
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition suricata.c:284
FileContainer * FileContainerAlloc(void)
allocate a FileContainer
Definition util-file.c:480
void FileContainerFree(FileContainer *ffc, const StreamingBufferConfig *cfg)
Free a FileContainer.
Definition util-file.c:516
#define STREAMING_BUFFER_CONFIG_INITIALIZER
void setenv(const char *name, const char *value, int overwrite)