Skip to content

Commit a137b64

Browse files
authored
Merge pull request #5687 from AdamKorcz/fuzz3
2 parents ee27cde + 0789a0c commit a137b64

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

contrib/fuzz/docker_fuzzer.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// +build gofuzz
2+
3+
/*
4+
Copyright The containerd Authors.
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
/*
17+
This fuzzer is run continuously by OSS-fuzz.
18+
It is stored in contrib/fuzz for organization,
19+
but in order to execute it, it must be moved to
20+
remotes/docker first.
21+
*/
22+
23+
package docker
24+
25+
import (
26+
"context"
27+
"fmt"
28+
"io/ioutil"
29+
"net/http"
30+
"net/http/httptest"
31+
"net/url"
32+
)
33+
34+
func FuzzFetcher(data []byte) int {
35+
dataLen := len(data)
36+
if dataLen == 0 {
37+
return -1
38+
}
39+
40+
s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
41+
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-%d/%d", 0, dataLen-1, dataLen))
42+
rw.Header().Set("content-length", fmt.Sprintf("%d", dataLen))
43+
rw.Write(data)
44+
}))
45+
defer s.Close()
46+
47+
u, err := url.Parse(s.URL)
48+
if err != nil {
49+
return 0
50+
}
51+
52+
f := dockerFetcher{&dockerBase{
53+
repository: "nonempty",
54+
}}
55+
host := RegistryHost{
56+
Client: s.Client(),
57+
Host: u.Host,
58+
Scheme: u.Scheme,
59+
Path: u.Path,
60+
}
61+
62+
ctx := context.Background()
63+
req := f.request(host, http.MethodGet)
64+
rc, err := f.open(ctx, req, "", 0)
65+
if err != nil {
66+
return 0
67+
}
68+
b, err := ioutil.ReadAll(rc)
69+
if err != nil {
70+
return 0
71+
}
72+
73+
expected := data
74+
if len(b) != len(expected) {
75+
panic("len of request is not equal to len of expected but should be")
76+
}
77+
return 1
78+
}

contrib/fuzz/oss_fuzz_build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright The containerd Authors.
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
cd "$(dirname "${BASH_SOURCE[0]}")"
18+
cd ../../
19+
20+
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzFiltersParse fuzz_filters_parse
21+
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzPlatformsParse fuzz_platforms_parse
22+
23+
mv contrib/fuzz/docker_fuzzer.go remotes/docker/
24+
compile_go_fuzzer github.com/containerd/containerd/remotes/docker FuzzFetcher fuzz_fetcher
25+
mv remotes/docker/docker_fuzzer.go contrib/fuzz/

0 commit comments

Comments
 (0)