Merge pull request #10326 from AdamKorcz/fuzz3

Add fuzzer and OSS-fuzz build script
This commit is contained in:
Kubernetes Prow Robot 2020-12-04 06:57:59 -08:00 committed by GitHub
commit 5ccbcb3056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 0 deletions

View File

@ -167,6 +167,7 @@ k8s.io/kops/protokube/pkg/hostmount
k8s.io/kops/protokube/pkg/protokube
k8s.io/kops/protokube/tests/integration/build_etcd_manifest
k8s.io/kops/tests/codecs
k8s.io/kops/tests/fuzz
k8s.io/kops/tests/integration/channel
k8s.io/kops/tests/integration/conversion
k8s.io/kops/upup/models

9
tests/fuzz/BUILD.bazel Normal file
View File

@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["fuzz.go"],
importpath = "k8s.io/kops/tests/fuzz",
visibility = ["//visibility:public"],
deps = ["//pkg/jsonutils:go_default_library"],
)

20
tests/fuzz/build.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Copyright 2020 The Kubernetes Authors.
#
# 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.
cp "$SRC"/AFL/dictionaries/json.dict "$OUT"/fuzz_write_token.dict
zip "$OUT"/fuzz_write_token_seed_corpus.zip "$SRC"/go-fuzz-corpus/json/corpus/*
compile_go_fuzzer k8s.io/kops/tests/fuzz FuzzWriteToken fuzz_write_token

40
tests/fuzz/fuzz.go Normal file
View File

@ -0,0 +1,40 @@
/*
Copyright 2020 The Kubernetes Authors.
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 fuzz
import (
"bytes"
"encoding/json"
"strings"
"k8s.io/kops/pkg/jsonutils"
)
func FuzzWriteToken(data []byte) int {
var buf bytes.Buffer
out := jsonutils.NewJSONStreamWriter(&buf)
in := json.NewDecoder(strings.NewReader(string(data)))
token, err := in.Token()
if err != nil {
return -1
}
err = out.WriteToken(token)
if err != nil {
return 0
}
return 1
}