summaryrefslogtreecommitdiffstats
path: root/tests/fuzz/test-fuzz.c
blob: a62c32609979a91949d9529bf9e4b10585d19a58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>

#include "util.h"

static void fuzz_parse_command(const char *buf)
{
	char **p = parse_command(buf);
	if (p)
		free(p);
}

int LLVMFuzzerTestOneInput(const uint8_t *input, size_t size)
{
	char *p = NULL;
	char *fields[] = { "sessionid", NULL, "path", NULL, "filename", NULL, "mimetype", NULL };
	char *buf = calloc(1, size+1);
	memcpy(buf, input, size);

	urldecode(buf);
	fuzz_parse_command(buf);
	p = canonicalize_path(buf, size+1);
	if (p)
		free(p);

	p = postdecode_fields(buf, size+1, fields, 4);
	if (!p)
		return 0;

	free(buf);

	return 0;
}