From 6e7e41d9f362b02f1f6f46a325425d1f0fd33759 Mon Sep 17 00:00:00 2001 From: Adam Korczynski Date: Mon, 11 May 2020 22:17:29 +0100 Subject: [PATCH] Added 2 fuzzers Signed-off-by: Adam Korczynski --- dfget/core/uploader/uploader_fuzz.go | 26 +++++++++++++++++++ supernode/daemon/mgr/cdn/cdn_fuzz.go | 37 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 dfget/core/uploader/uploader_fuzz.go create mode 100644 supernode/daemon/mgr/cdn/cdn_fuzz.go diff --git a/dfget/core/uploader/uploader_fuzz.go b/dfget/core/uploader/uploader_fuzz.go new file mode 100644 index 000000000..7480c3ba6 --- /dev/null +++ b/dfget/core/uploader/uploader_fuzz.go @@ -0,0 +1,26 @@ +/* + * Copyright The Dragonfly 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 uploader + +func FuzzParseParams(data []byte) int { + s := string(data) + _, err := parseParams(s, s, s) + if err != nil { + return 0 + } + return 1 +} diff --git a/supernode/daemon/mgr/cdn/cdn_fuzz.go b/supernode/daemon/mgr/cdn/cdn_fuzz.go new file mode 100644 index 000000000..087d1f6c2 --- /dev/null +++ b/supernode/daemon/mgr/cdn/cdn_fuzz.go @@ -0,0 +1,37 @@ +/* + * Copyright The Dragonfly 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 cdn + +import ( + "bytes" + "context" + "io/ioutil" + + "github.com/sirupsen/logrus" +) + +func Fuzz(data []byte) int { + // Don't spam output with parse failures + logrus.SetOutput(ioutil.Discard) + r := bytes.NewReader(data) + sr := newSuperReader() + _, err := sr.readFile(context.Background(), r, true, true) + if err != nil { + return 0 + } + return 1 +}