Skip to content

Commit

Permalink
setup fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
ericchiang committed Dec 10, 2017
1 parent 19807d8 commit 87d9aaf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
workdir/
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: test
test:
go test -v -i
go test -v

.PHONY: fuzz
fuzz:
mkdir -p bin
go-fuzz-build -o=bin/css-fuzz.zip github.com/ericchiang/css
mkdir -p workdir/corpus
./scripts/init-fuzz-corpus
go-fuzz -bin=bin/css-fuzz.zip -workdir=workdir

.PHONY: clean
clean:
rm -rf bin
rm -rf workdir
10 changes: 10 additions & 0 deletions fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build gofuzz

package css

func Fuzz(data []byte) int {
if _, err := Compile(string(data)); err != nil {
return 0
}
return 1
}
3 changes: 3 additions & 0 deletions scripts/init-fuzz-corpus
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

awk '{ print $0 > "workdir/corpus/example-"NR".css"}' < testdata/fuzz-samples.css
20 changes: 20 additions & 0 deletions testdata/fuzz-samples.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
span > p, p
p ~ span
div > p
span > p
div div
div *
div .hi
p :empty
a.foo
#foo
a[id=foo]
p:empty
a:nth-child(odd)
[id=foo]
[id = 'foo']
[id="foo"]
[id|="hello"]
[id^="hello"]
[id$="hello"]
[id*="hello"]

0 comments on commit 87d9aaf

Please sign in to comment.