Add fuzz testing corpus and build

This commit is contained in:
2025-10-15 10:50:51 +02:00
parent c50655682e
commit 246d62c029
117 changed files with 326 additions and 3 deletions
+1
View File
@@ -3,6 +3,7 @@ coverage_html/
test test
test.exe test.exe
test_cov test_cov
fuzz
wl wl
wl.exe wl.exe
wl_cov wl_cov
+16
View File
@@ -1,4 +1,7 @@
AFL_CC ?= afl-clang-fast
AFL_CXX ?= afl-clang-fast++
.PHONY: all coverage coverage_report install uninstall .PHONY: all coverage coverage_report install uninstall
all: wl all: wl
@@ -19,6 +22,19 @@ coverage_report:
lcov --remove coverage.info '/usr/*' --output-file coverage_filtered.info lcov --remove coverage.info '/usr/*' --output-file coverage_filtered.info
genhtml coverage_filtered.info --output-directory coverage_html --title "WL Template Engine Coverage" 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 install: wl
sudo cp wl /usr/local/bin sudo cp wl /usr/local/bin
+5 -3
View File
@@ -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")
+88
View File
@@ -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;
}
+1
View File
@@ -0,0 +1 @@
1
+1
View File
@@ -0,0 +1 @@
0.4
+1
View File
@@ -0,0 +1 @@
none
+1
View File
@@ -0,0 +1 @@
true
+1
View File
@@ -0,0 +1 @@
false
+1
View File
@@ -0,0 +1 @@
"Hello, world!"
+1
View File
@@ -0,0 +1 @@
'Hello, world!'
+1
View File
@@ -0,0 +1 @@
"\\"
+1
View File
@@ -0,0 +1 @@
"\n"
+1
View File
@@ -0,0 +1 @@
"\t"
+1
View File
@@ -0,0 +1 @@
"\r"
+1
View File
@@ -0,0 +1 @@
"\""
+1
View File
@@ -0,0 +1 @@
"\'"
+1
View File
@@ -0,0 +1 @@
"\xFF"
+1
View File
@@ -0,0 +1 @@
"\x0F"
+1
View File
@@ -0,0 +1 @@
"\xF0"
+1
View File
@@ -0,0 +1 @@
[1, 2, 3]
+1
View File
@@ -0,0 +1 @@
+{}
+1
View File
@@ -0,0 +1 @@
+{a:1}
+1
View File
@@ -0,0 +1 @@
+{a:1,b:2,c:3}
+1
View File
@@ -0,0 +1 @@
10-1-2
+1
View File
@@ -0,0 +1 @@
1+2*3
+1
View File
@@ -0,0 +1 @@
(1+2)*3
+1
View File
@@ -0,0 +1 @@
1+(2*3)
+1
View File
@@ -0,0 +1 @@
1+2
+1
View File
@@ -0,0 +1 @@
2-1
+1
View File
@@ -0,0 +1 @@
1-2
+1
View File
@@ -0,0 +1 @@
2*3
+1
View File
@@ -0,0 +1 @@
2/3
+1
View File
@@ -0,0 +1 @@
4/2
+1
View File
@@ -0,0 +1 @@
0%2
+1
View File
@@ -0,0 +1 @@
3%2
+1
View File
@@ -0,0 +1 @@
1.0+2.0
+1
View File
@@ -0,0 +1 @@
2.0-1.0
+1
View File
@@ -0,0 +1 @@
1.0-2.0
+1
View File
@@ -0,0 +1 @@
2.0*3.0
+1
View File
@@ -0,0 +1 @@
2.0/3.0
+1
View File
@@ -0,0 +1 @@
4.0/2.0
+1
View File
@@ -0,0 +1 @@
1+2.0
+1
View File
@@ -0,0 +1 @@
2-1.0
+1
View File
@@ -0,0 +1 @@
1-2.0
+1
View File
@@ -0,0 +1 @@
2*3.0
+1
View File
@@ -0,0 +1 @@
2/3.0
+1
View File
@@ -0,0 +1 @@
4/2.0
+1
View File
@@ -0,0 +1 @@
1.0+2
+1
View File
@@ -0,0 +1 @@
2.0-1
+1
View File
@@ -0,0 +1 @@
1.0-2
+1
View File
@@ -0,0 +1 @@
2.0*3
+1
View File
@@ -0,0 +1 @@
2.0/3
+1
View File
@@ -0,0 +1 @@
4.0/2
+1
View File
@@ -0,0 +1 @@
len []
+1
View File
@@ -0,0 +1 @@
len [1, 2, 3]
+1
View File
@@ -0,0 +1 @@
len {}
+1
View File
@@ -0,0 +1 @@
len {a:1}
+1
View File
@@ -0,0 +1 @@
len {a:1,b:2,c:3}
+1
View File
@@ -0,0 +1 @@
-12
+1
View File
@@ -0,0 +1 @@
-12.34
+1
View File
@@ -0,0 +1 @@
1<2
+1
View File
@@ -0,0 +1 @@
2<1
+1
View File
@@ -0,0 +1 @@
1>2
+1
View File
@@ -0,0 +1 @@
2>1
+1
View File
@@ -0,0 +1 @@
1==1
+1
View File
@@ -0,0 +1 @@
1==2
+1
View File
@@ -0,0 +1 @@
1!=1
+1
View File
@@ -0,0 +1 @@
1!=2
+2
View File
@@ -0,0 +1,2 @@
let a = 1
a
+3
View File
@@ -0,0 +1,3 @@
let a = 1
a = 2
a
+1
View File
@@ -0,0 +1 @@
[5, 6, 7][0]
+1
View File
@@ -0,0 +1 @@
[5, 6, 7][1]
+1
View File
@@ -0,0 +1 @@
[5, 6, 7][2]
+1
View File
@@ -0,0 +1 @@
+{a:5,b:6,c:7}.a
+1
View File
@@ -0,0 +1 @@
+{a:5,b:6,c:7}.b
+1
View File
@@ -0,0 +1 @@
+{a:5,b:6,c:7}.c
+1
View File
@@ -0,0 +1 @@
+{a:5,b:6,c:7}['a']
+1
View File
@@ -0,0 +1 @@
+{a:5,b:6,c:7}['b']
+1
View File
@@ -0,0 +1 @@
+{a:5,b:6,c:7}['c']
+5
View File
@@ -0,0 +1,5 @@
let x = 1
{
let x = 2
x
}
+3
View File
@@ -0,0 +1,3 @@
let x = {a:5,b:6,c:7}
x.a = true
x
+3
View File
@@ -0,0 +1,3 @@
let x = {a:5,b:6,c:7}
x.b = true
x
+3
View File
@@ -0,0 +1,3 @@
let x = {a:5,b:6,c:7}
x.c = true
x
+3
View File
@@ -0,0 +1,3 @@
let x = {a:5,b:6,c:7}
x['a'] = true
x
+3
View File
@@ -0,0 +1,3 @@
let x = {a:5,b:6,c:7}
x['b'] = true
x
+3
View File
@@ -0,0 +1,3 @@
let x = {a:5,b:6,c:7}
x['c'] = true
x
+4
View File
@@ -0,0 +1,4 @@
let a
let b
let c
a = b = c = 5
+7
View File
@@ -0,0 +1,7 @@
let a
let b
let c
a = b = c = 5
a
b
c
+3
View File
@@ -0,0 +1,3 @@
if 1 < 2:
1
2
+3
View File
@@ -0,0 +1,3 @@
if 1 > 2:
1
2
+5
View File
@@ -0,0 +1,5 @@
if 1 < 2:
1
else
2
3
+5
View File
@@ -0,0 +1,5 @@
if 1 > 2:
1
else
2
3
+5
View File
@@ -0,0 +1,5 @@
let i = 0
while i < 3: {
true
i = i + 1
}
+2
View File
@@ -0,0 +1,2 @@
for a in ['A', 'B', 'C']:
a
+4
View File
@@ -0,0 +1,4 @@
for a, b in ['A', 'B', 'C']: {
a
b
}
+2
View File
@@ -0,0 +1,2 @@
for a in {x:1,y:2,z:3}:
a
+4
View File
@@ -0,0 +1,4 @@
for a, b in {x:1,y:2,z:3}: {
a
b
}
+2
View File
@@ -0,0 +1,2 @@
procedure P()
0
+2
View File
@@ -0,0 +1,2 @@
procedure P(a)
a

Some files were not shown because too many files have changed in this diff Show More