Skip to content

Commit

Permalink
Added fuzzer to integrate with OSS-fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKorcz committed Dec 2, 2020
1 parent ead7143 commit b33b159
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions hack/.packages
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/fuzz/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
17 changes: 17 additions & 0 deletions tests/fuzz/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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.

compile_go_fuzzer k8s.io/kops/tests/fuzz FuzzWriteToken fuzz_write_token
40 changes: 40 additions & 0 deletions tests/fuzz/fuzz.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b33b159

Please sign in to comment.