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 "
util-base64.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
,
size_t
dest_size)
18
{
19
uint8_t *dest = malloc(dest_size);
20
if
(dest == NULL)
21
return
;
22
23
for
(uint8_t mode = Base64ModeRelax; mode <= Base64ModeRFC4648; mode++) {
24
uint32_t consumed_bytes = 0;
25
uint32_t decoded_bytes = 0;
26
27
DecodeBase64
(dest, dest_size,
src
,
len
, &consumed_bytes, &decoded_bytes, mode);
28
}
29
30
free(dest);
31
}
32
33
int
LLVMFuzzerTestOneInput
(
const
uint8_t *data,
size_t
size)
34
{
35
if
(initialized == 0) {
36
// Redirects logs to /dev/null
37
setenv
(
"SC_LOG_OP_IFACE"
,
"file"
, 0);
38
setenv
(
"SC_LOG_FILE"
,
"/dev/null"
, 0);
39
// global init
40
InitGlobal
();
41
SCRunmodeSet
(
RUNMODE_UNITTEST
);
42
initialized = 1;
43
}
44
45
if
(size <
BLK_SIZE
)
46
return
0;
47
48
uint32_t dest_size = (uint32_t)(data[0] << 8) | (uint32_t)(data[1]);
49
Base64FuzzTest(data +
BLK_SIZE
, size -
BLK_SIZE
, dest_size);
50
51
return
0;
52
}
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:266
util-base64.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition:
fuzz_decodebase64.c:33
DecodeBase64
Base64Ecode DecodeBase64(uint8_t *dest, uint32_t dest_size, const uint8_t *src, uint32_t len, uint32_t *consumed_bytes, uint32_t *decoded_bytes, DetectBase64Mode mode)
Decodes a base64-encoded string buffer into an ascii-encoded byte buffer.
Definition:
util-base64.c:276
setenv
void setenv(const char *name, const char *value, int overwrite)
suricata-common.h
BLK_SIZE
#define BLK_SIZE
Definition:
fuzz_decodebase64.c:11
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
src
tests
fuzz
fuzz_decodebase64.c
Generated on Sat Sep 7 2024 23:30:36 for suricata by
1.8.18