Set up fuzzing with go-fuzz
This commit is contained in:
parent
7a8e90f786
commit
8e154c2fd8
3 changed files with 32 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
gh-pages/
|
/gh-pages/
|
||||||
/go-org
|
/go-org
|
||||||
|
/fuzz
|
||||||
|
/org-fuzz.zip
|
10
Makefile
10
Makefile
|
@ -32,3 +32,13 @@ generate-gh-pages: build
|
||||||
.PHONY: generate-fixtures
|
.PHONY: generate-fixtures
|
||||||
generate-fixtures: build
|
generate-fixtures: build
|
||||||
./etc/generate-fixtures
|
./etc/generate-fixtures
|
||||||
|
|
||||||
|
.PHONY: fuzz
|
||||||
|
fuzz: build
|
||||||
|
@echo also see "http://lcamtuf.coredump.cx/afl/README.txt"
|
||||||
|
go get github.com/dvyukov/go-fuzz/go-fuzz
|
||||||
|
go get github.com/dvyukov/go-fuzz/go-fuzz-build
|
||||||
|
mkdir -p fuzz fuzz/corpus
|
||||||
|
cp org/testdata/*.org fuzz/corpus
|
||||||
|
go-fuzz-build github.com/niklasfasching/go-org/org
|
||||||
|
go-fuzz -bin=./org-fuzz.zip -workdir=fuzz
|
||||||
|
|
19
org/fuzz.go
Normal file
19
org/fuzz.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// +build gofuzz
|
||||||
|
|
||||||
|
package org
|
||||||
|
|
||||||
|
import "bytes"
|
||||||
|
|
||||||
|
// Fuzz function to be used by https://github.com/dvyukov/go-fuzz
|
||||||
|
func Fuzz(data []byte) int {
|
||||||
|
d := NewDocument().Silent().Parse(bytes.NewReader(data))
|
||||||
|
_, err := d.Write(NewOrgWriter())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_, err = d.Write(NewHTMLWriter())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue