mirror of https://github.com/google/oss-fuzz.git
Go json coverage (#4689)
* Good fuzz target for golang coverage with modules * Place target in right directory for go-json-iterator So that coverage gets access to the right package
This commit is contained in:
parent
bb8b2fb354
commit
91a6a12dbe
|
@ -38,7 +38,13 @@ if [[ $SANITIZER = *coverage* ]]; then
|
||||||
sed -i -e 's/TestFuzzCorpus/Test'$function'Corpus/' ./"${function,,}"_test.go
|
sed -i -e 's/TestFuzzCorpus/Test'$function'Corpus/' ./"${function,,}"_test.go
|
||||||
|
|
||||||
echo "#/bin/sh" > $OUT/$fuzzer
|
echo "#/bin/sh" > $OUT/$fuzzer
|
||||||
echo "cd $path" >> $OUT/$fuzzer
|
if [[ ${GO111MODULE:-} = on ]]; then
|
||||||
|
echo "export GO111MODULE=on" >> $OUT/$fuzzer
|
||||||
|
echo "cd ../pkg/mod/"`go list -m $basemod | sed 's/ /@/'` >> $OUT/$fuzzer
|
||||||
|
echo "cd ./"`echo $path | cut -d/ -f4-` >> $OUT/$fuzzer
|
||||||
|
else
|
||||||
|
echo "cd $path" >> $OUT/$fuzzer
|
||||||
|
fi
|
||||||
echo "go test -run Test${function}Corpus -v $tags -coverprofile \$1 " >> $OUT/$fuzzer
|
echo "go test -run Test${function}Corpus -v $tags -coverprofile \$1 " >> $OUT/$fuzzer
|
||||||
chmod +x $OUT/$fuzzer
|
chmod +x $OUT/$fuzzer
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,5 @@
|
||||||
FROM gcr.io/oss-fuzz-base/base-builder
|
FROM gcr.io/oss-fuzz-base/base-builder
|
||||||
RUN go get github.com/json-iterator/go
|
RUN go get github.com/json-iterator/go
|
||||||
|
|
||||||
RUN mkdir fuzz
|
COPY fuzz_json.go $GOPATH/src/github.com/json-iterator/go/
|
||||||
COPY fuzz_json.go fuzz
|
|
||||||
COPY build.sh $SRC/
|
COPY build.sh $SRC/
|
||||||
WORKDIR fuzz
|
|
||||||
|
|
|
@ -16,5 +16,4 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
compile_go_fuzzer github.com/json-iterator/go Fuzz fuzz_json
|
||||||
compile_go_fuzzer . Fuzz fuzz_json
|
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
// Use of this source code is governed by Apache 2 LICENSE.
|
// Use of this source code is governed by Apache 2 LICENSE.
|
||||||
// Modified from original file https://github.com/dvyukov/go-fuzz-corpus/blob/master/json/json.go
|
// Modified from original file https://github.com/dvyukov/go-fuzz-corpus/blob/master/json/json.go
|
||||||
|
|
||||||
package jsonfuzz
|
package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +20,7 @@ func Fuzz(data []byte) int {
|
||||||
func() interface{} { return new(S) },
|
func() interface{} { return new(S) },
|
||||||
} {
|
} {
|
||||||
v := ctor()
|
v := ctor()
|
||||||
if jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, v) != nil {
|
if ConfigCompatibleWithStandardLibrary.Unmarshal(data, v) != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
score = 1
|
score = 1
|
||||||
|
@ -36,12 +35,12 @@ func Fuzz(data []byte) int {
|
||||||
panic("not equal")
|
panic("not equal")
|
||||||
}
|
}
|
||||||
|
|
||||||
data1, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(v)
|
data1, err := ConfigCompatibleWithStandardLibrary.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
v1 := ctor()
|
v1 := ctor()
|
||||||
if jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data1, v1) != nil {
|
if ConfigCompatibleWithStandardLibrary.Unmarshal(data1, v1) != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(v, v1) {
|
if !reflect.DeepEqual(v, v1) {
|
||||||
|
@ -85,9 +84,9 @@ type Marshaller struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Marshaller) MarshalJSON() ([]byte, error) {
|
func (m *Marshaller) MarshalJSON() ([]byte, error) {
|
||||||
return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(m.v)
|
return ConfigCompatibleWithStandardLibrary.Marshal(m.v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Marshaller) UnmarshalJSON(data []byte) error {
|
func (m *Marshaller) UnmarshalJSON(data []byte) error {
|
||||||
return jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, &m.v)
|
return ConfigCompatibleWithStandardLibrary.Unmarshal(data, &m.v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue