Skip to content

Commit 4feb2b9

Browse files
committed
add fuzzing
1 parent 1cc165d commit 4feb2b9

File tree

10 files changed

+34
-3
lines changed

10 files changed

+34
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.o
2-
/color
2+
/test
3+
/fuzz
4+
/output

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
CXXFLAGS = -std=c++11 -Wall -Wextra -Wpedantic -Weverything -Wno-c++98-compat -Wno-missing-prototypes -Wno-padded -Wno-unused-parameter
1+
CXXFLAGS = -std=c++11 -Wall -Wextra -Wpedantic -Wno-unused-parameter
22

33
build: test
44

55
test: csscolorparser.o test.o
66
$(CXX) $(CXXFLAGS) -o $@ $^
77

8+
fuzz: csscolorparser.o fuzz.o
9+
afl-clang-fast++ $(CXXFLAGS) -o $@ $^
10+
11+
fuzz.o: fuzz.cpp
12+
afl-clang-fast++ $(CXXFLAGS) -c -o $@ $^
13+
814
%.o: %.cpp
915
$(CXX) $(CXXFLAGS) -c -o $@ $^
1016

1117
clean:
12-
rm -rf *.o test
18+
rm -rf *.o test fuzz
1319

1420
.PHONY: clean

fuzz.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "csscolorparser.hpp"
2+
3+
#include <iostream>
4+
#include <istream>
5+
6+
int main(int argc, char* argv[]) {
7+
while (__AFL_LOOP(1000)) {
8+
// Pass stdin to the function.
9+
std::cin >> std::noskipws;
10+
CSSColorParser::parse({ std::istream_iterator<char>(std::cin), std::istream_iterator<char>() });
11+
}
12+
return 0;
13+
}

fuzz.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
3+
make fuzz
4+
afl-fuzz -i input -o output -- ./fuzz

input/a

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rgba(255, 128, 12, 0.5)

input/b

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#fff

input/c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#ff0011

input/d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
slateblue

input/e

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ffffff

input/f

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hsla(900, 15%, 90%, 0.5)

0 commit comments

Comments
 (0)