suricata
fuzz_decodebase64.c
Go to the documentation of this file.
1 /**
2  * @file
3  * @author Shivani Bhardwaj <shivani@oisf.net>
4  * fuzz target for DecodeBase64
5  */
6 
7 #include "suricata-common.h"
8 #include "suricata.h"
9 #include "rust.h"
10 
11 #define BLK_SIZE 2
12 
13 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
14 
15 static int initialized = 0;
16 
17 static void Base64FuzzTest(const uint8_t *src, size_t len)
18 {
19  uint32_t decoded_len = Base64DecodeBufferSize(len);
20  uint8_t *decoded = SCCalloc(decoded_len, sizeof(uint8_t));
21 
22  for (uint8_t mode = Base64ModeRFC2045; mode <= Base64ModeStrict; mode++) {
23  (void)Base64Decode(src, len, mode, decoded);
24  }
25 
26  SCFree(decoded);
27 }
28 
29 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
30 {
31  if (initialized == 0) {
32  // Redirects logs to /dev/null
33  setenv("SC_LOG_OP_IFACE", "file", 0);
34  setenv("SC_LOG_FILE", "/dev/null", 0);
35  // global init
36  InitGlobal();
38  initialized = 1;
39  }
40 
41  if (size < BLK_SIZE)
42  return 0;
43 
44  Base64FuzzTest(data, size);
45 
46  return 0;
47 }
len
uint8_t len
Definition: app-layer-dnp3.h:2
RUNMODE_UNITTEST
@ RUNMODE_UNITTEST
Definition: runmodes.h:40
SCRunmodeSet
void SCRunmodeSet(int run_mode)
Set the current run mode.
Definition: suricata.c:265
rust.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: fuzz_decodebase64.c:29
setenv
void setenv(const char *name, const char *value, int overwrite)
suricata-common.h
BLK_SIZE
#define BLK_SIZE
Definition: fuzz_decodebase64.c:11
SCFree
#define SCFree(p)
Definition: util-mem.h:61
src
uint16_t src
Definition: app-layer-dnp3.h:5
suricata.h
InitGlobal
int InitGlobal(void)
Global initialization common to all runmodes.
Definition: suricata.c:2856
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53