a62c32609979a91949d9529bf9e4b10585d19a58
[project/cgi-io.git] / tests / fuzz / test-fuzz.c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include <stddef.h>
6 #include <string.h>
7 #include <fcntl.h>
8 #include <errno.h>
9 #include <unistd.h>
10
11 #include <sys/types.h>
12 #include <sys/stat.h>
13
14 #include "util.h"
15
16 static void fuzz_parse_command(const char *buf)
17 {
18 char **p = parse_command(buf);
19 if (p)
20 free(p);
21 }
22
23 int LLVMFuzzerTestOneInput(const uint8_t *input, size_t size)
24 {
25 char *p = NULL;
26 char *fields[] = { "sessionid", NULL, "path", NULL, "filename", NULL, "mimetype", NULL };
27 char *buf = calloc(1, size+1);
28 memcpy(buf, input, size);
29
30 urldecode(buf);
31 fuzz_parse_command(buf);
32 p = canonicalize_path(buf, size+1);
33 if (p)
34 free(p);
35
36 p = postdecode_fields(buf, size+1, fields, 4);
37 if (!p)
38 return 0;
39
40 free(buf);
41
42 return 0;
43 }