Skip to content

Commit 7823794

Browse files
author
Dmitri Tikhonov
committed
Initial commit
1 parent fdef421 commit 7823794

9 files changed

+4292
-1
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 LiteSpeed Tech
3+
Copyright (c) 2020 LiteSpeed Technologies Inc
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CFLAGS=-Wall
2+
3+
all: test-sfp
4+
5+
fuzz: fuzz-sfp
6+
7+
test-sfp: test-sfp.c ls-sfparser.c ls-sfparser.h
8+
cc ${CFLAGS} -o test-sfp test-sfp.c ls-sfparser.c
9+
10+
fuzz-sfp: fuzz-sfp.c ls-sfparser.c ls-sfparser.h
11+
afl-gcc -O3 -o fuzz-sfp fuzz-sfp.c ls-sfparser.c
12+
#cc -g3 -o fuzz-sfp fuzz-sfp.c ls-sfparser.c
13+
14+
ls-sfparser.c:
15+
16+
ls-sfparser.c: ls-sfparser.l
17+
flex -o ls-sfparser.c ls-sfparser.l
18+
19+
clean:
20+
rm -vf test-sfp fuzz-sfp

fuzz-sfp.c

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
#include "ls-sfparser.h"
6+
7+
8+
static int
9+
callback (void *user_data, enum ls_sf_dt type, char *str)
10+
{
11+
return 0;
12+
}
13+
14+
15+
int
16+
main (int argc, char **argv)
17+
{
18+
int ret, tlt;
19+
char *input;
20+
size_t input_sz;
21+
FILE *file;
22+
char buf[0x10000];
23+
char mem[0x4000];
24+
25+
if (argc != 3 && argc != 2)
26+
{
27+
usage:
28+
printf(
29+
"Usage: %s top-level-type [string]\n"
30+
"\n"
31+
"<top-level-type> is a number:\n"
32+
" 0 Dictionary\n"
33+
" 1 List\n"
34+
" 2 Item\n"
35+
"\n"
36+
"Examine exit status to see whether <string> parsed correctly.\n"
37+
"If <string> is not specified, read input from stdin.\n"
38+
"\n", argv[0]);
39+
return EXIT_FAILURE;
40+
}
41+
42+
tlt = atoi(argv[1]);
43+
if (!(tlt >= 0 && tlt <= 2))
44+
goto usage;
45+
46+
file = fopen(argv[2], "rb");
47+
if (!file)
48+
exit(EXIT_FAILURE);
49+
50+
input_sz = fread(buf, 1, sizeof(buf), file);
51+
if (input_sz == 0)
52+
exit(EXIT_FAILURE);
53+
input = buf;
54+
55+
ret = ls_sf_parse((enum ls_sf_tlt) tlt, input, input_sz, callback,
56+
NULL, mem, sizeof(mem));
57+
fclose(file);
58+
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
59+
}

0 commit comments

Comments
 (0)