mirror of https://github.com/google/oss-fuzz.git
[golang] Added 2 fuzzers (#5437)
* [golang] Added 2 fuzzers * Change fuzzer to call exported targets * Added fuzzer
This commit is contained in:
parent
342f9f5cf4
commit
66d7e5f1cf
|
@ -17,6 +17,6 @@
|
|||
FROM gcr.io/oss-fuzz-base/base-builder
|
||||
|
||||
RUN git clone --depth 1 https://github.com/dvyukov/go-fuzz-corpus golang
|
||||
COPY build.sh $SRC/
|
||||
COPY build.sh math_big_fuzzer.go $SRC/
|
||||
|
||||
WORKDIR $SRC/golang
|
||||
|
|
|
@ -15,8 +15,14 @@
|
|||
# These two dependencies cause build issues and are not used by oss-fuzz:
|
||||
rm -r sqlparser
|
||||
rm -r parser
|
||||
|
||||
mkdir math && cp $SRC/math_big_fuzzer.go ./math/
|
||||
|
||||
go mod init "github.com/dvyukov/go-fuzz-corpus"
|
||||
export FUZZ_ROOT="github.com/dvyukov/go-fuzz-corpus"
|
||||
compile_go_fuzzer $FUZZ_ROOT/math FuzzBigIntCmp1 big_cmp_fuzzer1
|
||||
compile_go_fuzzer $FUZZ_ROOT/math FuzzBigIntCmp2 big_cmp_fuzzer2
|
||||
compile_go_fuzzer $FUZZ_ROOT/math FuzzRatSetString big_rat_fuzzer
|
||||
compile_go_fuzzer $FUZZ_ROOT/asn1 Fuzz asn_fuzzer
|
||||
compile_go_fuzzer $FUZZ_ROOT/csv Fuzz csv_fuzzer
|
||||
compile_go_fuzzer $FUZZ_ROOT/elliptic Fuzz elliptic_fuzzer
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2021 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
|
||||
package mathfuzzer
|
||||
|
||||
import "math/big"
|
||||
|
||||
func FuzzBigIntCmp1(data []byte) int {
|
||||
if !isDivisibleBy(len(data), 2) {
|
||||
return -1
|
||||
}
|
||||
i1 := new(big.Int)
|
||||
i2 := new(big.Int)
|
||||
|
||||
half := len(data) / 2
|
||||
|
||||
halfOne := data[:half]
|
||||
halfTwo := data[half:]
|
||||
|
||||
i1.SetBytes(halfOne)
|
||||
i2.SetBytes(halfTwo)
|
||||
|
||||
i1.Cmp(i2)
|
||||
return 1
|
||||
}
|
||||
|
||||
func FuzzBigIntCmp2(data []byte) int {
|
||||
if !isDivisibleBy(len(data), 2) {
|
||||
return -1
|
||||
}
|
||||
x, y := new(big.Int), new(big.Int)
|
||||
half := len(data)/2
|
||||
if err := x.UnmarshalText(data[:half]); err != nil {
|
||||
return 0
|
||||
}
|
||||
if err := y.UnmarshalText(data[half:]); err != nil {
|
||||
return 0
|
||||
}
|
||||
x.Cmp(y)
|
||||
return 1
|
||||
}
|
||||
|
||||
func FuzzRatSetString(data []byte) int {
|
||||
_, _ = new(big.Rat).SetString(string(data))
|
||||
return 1
|
||||
}
|
||||
|
||||
func isDivisibleBy(n int, divisibleby int) bool {
|
||||
return (n % divisibleby) == 0
|
||||
}
|
Loading…
Reference in New Issue