forked from opencontainers/runc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencontainers#2841 from AdamKorcz/fuzz1
tests: Move fuzzers upstream
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// +build gofuzz | ||
|
||
package configs | ||
|
||
func FuzzUnmarshalJSON(data []byte) int { | ||
hooks := Hooks{} | ||
_ = hooks.UnmarshalJSON(data) | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// +build gofuzz | ||
|
||
package system | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/opencontainers/runc/libcontainer/user" | ||
) | ||
|
||
func FuzzUIDMap(data []byte) int { | ||
uidmap, _ := user.ParseIDMap(strings.NewReader(string(data))) | ||
_ = UIDMapInUserNS(uidmap) | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// +build gofuzz | ||
|
||
package user | ||
|
||
import ( | ||
"io" | ||
"strings" | ||
) | ||
|
||
func IsDivisbleBy(n int, divisibleby int) bool { | ||
return (n % divisibleby) == 0 | ||
} | ||
|
||
func FuzzUser(data []byte) int { | ||
if len(data) == 0 { | ||
return -1 | ||
} | ||
if !IsDivisbleBy(len(data), 5) { | ||
return -1 | ||
} | ||
|
||
var divided [][]byte | ||
|
||
chunkSize := len(data) / 5 | ||
|
||
for i := 0; i < len(data); i += chunkSize { | ||
end := i + chunkSize | ||
|
||
divided = append(divided, data[i:end]) | ||
} | ||
|
||
_, _ = ParsePasswdFilter(strings.NewReader(string(divided[0])), nil) | ||
|
||
var passwd, group io.Reader | ||
|
||
group = strings.NewReader(string(divided[1])) | ||
_, _ = GetAdditionalGroups([]string{string(divided[2])}, group) | ||
|
||
passwd = strings.NewReader(string(divided[3])) | ||
_, _ = GetExecUser(string(divided[4]), nil, passwd, group) | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This file is only meant to be run by OSS-fuzz and will not work | ||
# if run outside of it. | ||
# The api, compile_go_fuzzer() is provided by the OSS-fuzz | ||
# environment and is a high level helper function for a series | ||
# of compilation and linking steps to build the fuzzers in the | ||
# OSS-fuzz environment. | ||
# More info about compile_go_fuzzer() can be found here: | ||
# https://google.github.io/oss-fuzz/getting-started/new-project-guide/go-lang/#buildsh | ||
compile_go_fuzzer ./libcontainer/system FuzzUIDMap id_map_fuzzer linux | ||
compile_go_fuzzer ./libcontainer/user FuzzUser user_fuzzer | ||
compile_go_fuzzer ./libcontainer/configs FuzzUnmarshalJSON configs_fuzzer |