Skip to content

Commit c3c276a

Browse files
committed
Fuzzing: Fix for OSS-fuzz issue 36825
Signed-off-by: AdamKorcz <[email protected]>
1 parent dd08c7a commit c3c276a

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

contrib/fuzz/container_fuzzer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ import (
4141
func init() {
4242
err := updatePathEnv()
4343
if err != nil {
44-
panic(err)
44+
fmt.Println(err)
4545
}
46-
4746
}
4847

4948
func tearDown() error {
@@ -130,7 +129,7 @@ func startDaemon(ctx context.Context, shouldTearDown bool) {
130129
// refuse a connection to it, and deleting it allows us
131130
// to create a new socket when invoking containerd.New()
132131
func deleteSocket() error {
133-
err := os.Remove("/run/containerd-test/containerd.sock")
132+
err := os.Remove(defaultAddress)
134133
if err != nil {
135134
return err
136135
}
@@ -143,7 +142,7 @@ func deleteSocket() error {
143142
// to $PATH, since the binaries are available there.
144143
func updatePathEnv() error {
145144
// Create test dir for socket
146-
err := os.MkdirAll("/run/containerd-test", 0777)
145+
err := os.MkdirAll(defaultState, 0777)
147146
if err != nil {
148147
return err
149148
}
@@ -273,7 +272,7 @@ func doFuzz(data []byte, shouldTearDown bool) int {
273272
if ctrd.cmd == nil {
274273
startDaemon(ctx, shouldTearDown)
275274
}
276-
client, err := containerd.New(address)
275+
client, err := containerd.New(defaultAddress)
277276
if err != nil {
278277
// The error here is most likely with the socket.
279278
// Deleting it will allow the creation of a new
@@ -282,6 +281,7 @@ func doFuzz(data []byte, shouldTearDown bool) int {
282281
return -1
283282
}
284283
defer client.Close()
284+
285285
f := fuzz.NewConsumer(data)
286286

287287
// Begin import tars:

contrib/fuzz/oss_fuzz_build.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ make EXTRA_FLAGS="-buildmode pie" \
5959
mkdir $OUT/containerd-binaries || true
6060
cd $SRC/containerd/bin && cp * $OUT/containerd-binaries/ && cd -
6161

62+
# Change defaultState and defaultAddress fron /run/containerd-test to /tmp/containerd-test:
63+
sed -i 's/\/run\/containerd-test/\/tmp\/containerd-test/g' $SRC/containerd/integration/client/client_unix_test.go
64+
6265
cd integration/client
66+
6367
# Rename all *_test.go to *_test_fuzz.go to use their declarations:
6468
for i in $( ls *_test.go ); do mv $i ./${i%.*}_fuzz.go; done
65-
# Remove windows test to avoid double declarations
69+
70+
# Remove windows test to avoid double declarations:
6671
rm ./client_windows_test_fuzz.go
6772
compile_go_fuzzer . FuzzCreateContainerNoTearDown fuzz_create_container_no_teardown
6873
compile_go_fuzzer . FuzzCreateContainerWithTearDown fuzz_create_container_with_teardown

0 commit comments

Comments
 (0)