Add fuzz testing corpus and build
This commit is contained in:
@@ -3,6 +3,7 @@ coverage_html/
|
||||
test
|
||||
test.exe
|
||||
test_cov
|
||||
fuzz
|
||||
wl
|
||||
wl.exe
|
||||
wl_cov
|
||||
@@ -1,4 +1,7 @@
|
||||
|
||||
AFL_CC ?= afl-clang-fast
|
||||
AFL_CXX ?= afl-clang-fast++
|
||||
|
||||
.PHONY: all coverage coverage_report install uninstall
|
||||
|
||||
all: wl
|
||||
@@ -19,6 +22,19 @@ coverage_report:
|
||||
lcov --remove coverage.info '/usr/*' --output-file coverage_filtered.info
|
||||
genhtml coverage_filtered.info --output-directory coverage_html --title "WL Template Engine Coverage"
|
||||
|
||||
fuzz: fuzz.c wl.c wl.h
|
||||
$(AFL_CC) fuzz.c wl.c -o fuzz \
|
||||
-g -O3 -Wall \
|
||||
-fsanitize=address,undefined \
|
||||
-fno-omit-frame-pointer
|
||||
|
||||
bugs: fuzz
|
||||
AFL_SKIP_CPUFREQ=1 afl-fuzz \
|
||||
-i fuzz_input \
|
||||
-o /tmp/fuzz_output \
|
||||
-m none \
|
||||
./fuzz
|
||||
|
||||
install: wl
|
||||
sudo cp wl /usr/local/bin
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
let username = <script>alert('You\'ve been HACKED!')</script>
|
||||
|
||||
<span>Hello, my name is \escape(username)</span>
|
||||
|
||||
procedure page(title, lang)
|
||||
<html lang="\{lang}">
|
||||
\{title}
|
||||
</html>
|
||||
|
||||
page("Hello, world!", "it")
|
||||
@@ -0,0 +1,88 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "wl.h"
|
||||
|
||||
#define MAX_INPUT_SIZE (64 * 1024) // 64KB max input
|
||||
#define ARENA_SIZE (1 << 20) // 1MB arena
|
||||
|
||||
// Persistent mode: AFL will call this loop many times without restarting
|
||||
__AFL_FUZZ_INIT();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Allocate arena once (outside the AFL loop)
|
||||
char *mem = malloc(ARENA_SIZE);
|
||||
if (mem == NULL) {
|
||||
fprintf(stderr, "Failed to allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Buffer for input
|
||||
unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF;
|
||||
|
||||
#ifdef __AFL_HAVE_MANUAL_CONTROL
|
||||
__AFL_INIT();
|
||||
#endif
|
||||
|
||||
// AFL persistent mode: loop up to 1000 times per process
|
||||
while (__AFL_LOOP(1000)) {
|
||||
int len = __AFL_FUZZ_TESTCASE_LEN;
|
||||
|
||||
// Limit input size
|
||||
if (len > MAX_INPUT_SIZE) {
|
||||
len = MAX_INPUT_SIZE;
|
||||
}
|
||||
|
||||
// Reset arena for each iteration
|
||||
WL_Arena arena = { mem, ARENA_SIZE, 0 };
|
||||
|
||||
// Initialize compiler
|
||||
WL_Compiler *c = wl_compiler_init(&arena);
|
||||
if (c == NULL) {
|
||||
continue; // Out of memory, skip this input
|
||||
}
|
||||
|
||||
// Try to compile the input
|
||||
WL_AddResult res = wl_compiler_add(
|
||||
c,
|
||||
(WL_String) { "", 0 }, // empty path
|
||||
(WL_String) { (char*)buf, len }
|
||||
);
|
||||
|
||||
// If compilation succeeded, try to link
|
||||
if (res.type == WL_ADD_LINK) {
|
||||
WL_Program program;
|
||||
int ret = wl_compiler_link(c, &program);
|
||||
|
||||
// If linking succeeded, optionally execute (for deeper fuzzing)
|
||||
if (ret == 0) {
|
||||
WL_Runtime *rt = wl_runtime_init(&arena, program);
|
||||
if (rt != NULL) {
|
||||
// Execute up to 1000 steps to avoid infinite loops
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
WL_EvalResult eval_res = wl_runtime_eval(rt);
|
||||
|
||||
if (eval_res.type == WL_EVAL_DONE ||
|
||||
eval_res.type == WL_EVAL_ERROR) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle syscalls/sysvars by pushing dummy values
|
||||
if (eval_res.type == WL_EVAL_SYSVAR) {
|
||||
wl_push_s64(rt, 42);
|
||||
} else if (eval_res.type == WL_EVAL_SYSCALL) {
|
||||
wl_push_s64(rt, 42);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Arena is automatically reset on next iteration
|
||||
}
|
||||
|
||||
free(mem);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
0.4
|
||||
@@ -0,0 +1 @@
|
||||
none
|
||||
@@ -0,0 +1 @@
|
||||
true
|
||||
@@ -0,0 +1 @@
|
||||
false
|
||||
@@ -0,0 +1 @@
|
||||
"Hello, world!"
|
||||
@@ -0,0 +1 @@
|
||||
'Hello, world!'
|
||||
@@ -0,0 +1 @@
|
||||
"\\"
|
||||
@@ -0,0 +1 @@
|
||||
"\n"
|
||||
@@ -0,0 +1 @@
|
||||
"\t"
|
||||
@@ -0,0 +1 @@
|
||||
"\r"
|
||||
@@ -0,0 +1 @@
|
||||
"\""
|
||||
@@ -0,0 +1 @@
|
||||
"\'"
|
||||
@@ -0,0 +1 @@
|
||||
"\xFF"
|
||||
@@ -0,0 +1 @@
|
||||
"\x0F"
|
||||
@@ -0,0 +1 @@
|
||||
"\xF0"
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3]
|
||||
@@ -0,0 +1 @@
|
||||
+{}
|
||||
@@ -0,0 +1 @@
|
||||
+{a:1}
|
||||
@@ -0,0 +1 @@
|
||||
+{a:1,b:2,c:3}
|
||||
@@ -0,0 +1 @@
|
||||
10-1-2
|
||||
@@ -0,0 +1 @@
|
||||
1+2*3
|
||||
@@ -0,0 +1 @@
|
||||
(1+2)*3
|
||||
@@ -0,0 +1 @@
|
||||
1+(2*3)
|
||||
@@ -0,0 +1 @@
|
||||
1+2
|
||||
@@ -0,0 +1 @@
|
||||
2-1
|
||||
@@ -0,0 +1 @@
|
||||
1-2
|
||||
@@ -0,0 +1 @@
|
||||
2*3
|
||||
@@ -0,0 +1 @@
|
||||
2/3
|
||||
@@ -0,0 +1 @@
|
||||
4/2
|
||||
@@ -0,0 +1 @@
|
||||
0%2
|
||||
@@ -0,0 +1 @@
|
||||
3%2
|
||||
@@ -0,0 +1 @@
|
||||
1.0+2.0
|
||||
@@ -0,0 +1 @@
|
||||
2.0-1.0
|
||||
@@ -0,0 +1 @@
|
||||
1.0-2.0
|
||||
@@ -0,0 +1 @@
|
||||
2.0*3.0
|
||||
@@ -0,0 +1 @@
|
||||
2.0/3.0
|
||||
@@ -0,0 +1 @@
|
||||
4.0/2.0
|
||||
@@ -0,0 +1 @@
|
||||
1+2.0
|
||||
@@ -0,0 +1 @@
|
||||
2-1.0
|
||||
@@ -0,0 +1 @@
|
||||
1-2.0
|
||||
@@ -0,0 +1 @@
|
||||
2*3.0
|
||||
@@ -0,0 +1 @@
|
||||
2/3.0
|
||||
@@ -0,0 +1 @@
|
||||
4/2.0
|
||||
@@ -0,0 +1 @@
|
||||
1.0+2
|
||||
@@ -0,0 +1 @@
|
||||
2.0-1
|
||||
@@ -0,0 +1 @@
|
||||
1.0-2
|
||||
@@ -0,0 +1 @@
|
||||
2.0*3
|
||||
@@ -0,0 +1 @@
|
||||
2.0/3
|
||||
@@ -0,0 +1 @@
|
||||
4.0/2
|
||||
@@ -0,0 +1 @@
|
||||
len []
|
||||
@@ -0,0 +1 @@
|
||||
len [1, 2, 3]
|
||||
@@ -0,0 +1 @@
|
||||
len {}
|
||||
@@ -0,0 +1 @@
|
||||
len {a:1}
|
||||
@@ -0,0 +1 @@
|
||||
len {a:1,b:2,c:3}
|
||||
@@ -0,0 +1 @@
|
||||
-12
|
||||
@@ -0,0 +1 @@
|
||||
-12.34
|
||||
@@ -0,0 +1 @@
|
||||
1<2
|
||||
@@ -0,0 +1 @@
|
||||
2<1
|
||||
@@ -0,0 +1 @@
|
||||
1>2
|
||||
@@ -0,0 +1 @@
|
||||
2>1
|
||||
@@ -0,0 +1 @@
|
||||
1==1
|
||||
@@ -0,0 +1 @@
|
||||
1==2
|
||||
@@ -0,0 +1 @@
|
||||
1!=1
|
||||
@@ -0,0 +1 @@
|
||||
1!=2
|
||||
@@ -0,0 +1,2 @@
|
||||
let a = 1
|
||||
a
|
||||
@@ -0,0 +1,3 @@
|
||||
let a = 1
|
||||
a = 2
|
||||
a
|
||||
@@ -0,0 +1 @@
|
||||
[5, 6, 7][0]
|
||||
@@ -0,0 +1 @@
|
||||
[5, 6, 7][1]
|
||||
@@ -0,0 +1 @@
|
||||
[5, 6, 7][2]
|
||||
@@ -0,0 +1 @@
|
||||
+{a:5,b:6,c:7}.a
|
||||
@@ -0,0 +1 @@
|
||||
+{a:5,b:6,c:7}.b
|
||||
@@ -0,0 +1 @@
|
||||
+{a:5,b:6,c:7}.c
|
||||
@@ -0,0 +1 @@
|
||||
+{a:5,b:6,c:7}['a']
|
||||
@@ -0,0 +1 @@
|
||||
+{a:5,b:6,c:7}['b']
|
||||
@@ -0,0 +1 @@
|
||||
+{a:5,b:6,c:7}['c']
|
||||
@@ -0,0 +1,5 @@
|
||||
let x = 1
|
||||
{
|
||||
let x = 2
|
||||
x
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
let x = {a:5,b:6,c:7}
|
||||
x.a = true
|
||||
x
|
||||
@@ -0,0 +1,3 @@
|
||||
let x = {a:5,b:6,c:7}
|
||||
x.b = true
|
||||
x
|
||||
@@ -0,0 +1,3 @@
|
||||
let x = {a:5,b:6,c:7}
|
||||
x.c = true
|
||||
x
|
||||
@@ -0,0 +1,3 @@
|
||||
let x = {a:5,b:6,c:7}
|
||||
x['a'] = true
|
||||
x
|
||||
@@ -0,0 +1,3 @@
|
||||
let x = {a:5,b:6,c:7}
|
||||
x['b'] = true
|
||||
x
|
||||
@@ -0,0 +1,3 @@
|
||||
let x = {a:5,b:6,c:7}
|
||||
x['c'] = true
|
||||
x
|
||||
@@ -0,0 +1,4 @@
|
||||
let a
|
||||
let b
|
||||
let c
|
||||
a = b = c = 5
|
||||
@@ -0,0 +1,7 @@
|
||||
let a
|
||||
let b
|
||||
let c
|
||||
a = b = c = 5
|
||||
a
|
||||
b
|
||||
c
|
||||
@@ -0,0 +1,3 @@
|
||||
if 1 < 2:
|
||||
1
|
||||
2
|
||||
@@ -0,0 +1,3 @@
|
||||
if 1 > 2:
|
||||
1
|
||||
2
|
||||
@@ -0,0 +1,5 @@
|
||||
if 1 < 2:
|
||||
1
|
||||
else
|
||||
2
|
||||
3
|
||||
@@ -0,0 +1,5 @@
|
||||
if 1 > 2:
|
||||
1
|
||||
else
|
||||
2
|
||||
3
|
||||
@@ -0,0 +1,5 @@
|
||||
let i = 0
|
||||
while i < 3: {
|
||||
true
|
||||
i = i + 1
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
for a in ['A', 'B', 'C']:
|
||||
a
|
||||
@@ -0,0 +1,4 @@
|
||||
for a, b in ['A', 'B', 'C']: {
|
||||
a
|
||||
b
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
for a in {x:1,y:2,z:3}:
|
||||
a
|
||||
@@ -0,0 +1,4 @@
|
||||
for a, b in {x:1,y:2,z:3}: {
|
||||
a
|
||||
b
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
procedure P()
|
||||
0
|
||||
@@ -0,0 +1,2 @@
|
||||
procedure P(a)
|
||||
a
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user