Skip to content

Commit

Permalink
add cpp fuzz func support && unit tests, add more const languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiden Wang committed Jun 23, 2022
1 parent e42af75 commit 9a0f160
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
10 changes: 10 additions & 0 deletions checks/raw/fuzzing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
fuzzerOSSFuzz = "OSSFuzz"
fuzzerClusterFuzzLite = "ClusterFuzzLite"
fuzzerBuiltInGo = "GoBuiltInFuzzer"
fuzzerBuiltInCpp = "CppBuiltInFuzzer"
// TODO: add more fuzzing check supports.
)

Expand Down Expand Up @@ -57,6 +58,15 @@ var languageFuzzSpecs = map[clients.LanguageName]languageFuzzConfig{
Desc: asPointer(
"Go fuzzing intelligently walks through the source code to report failures and find vulnerabilities."),
},
clients.Cpp: {
filePattern: "fuzz_*.cpp",
Name: fuzzerBuiltInCpp,
funcPattern: `extern\s+[("C")\s]*[\w\*]+\s+(\w*((?i)fuzz)+\w*)+\s*\([\w* ,]*\)`,
URL: asPointer("https://help.code-intelligence.com/create-a-c-fuzz-test"),
Desc: asPointer(
"C++ Fuzz This Function.",
),
},
// TODO: add more language-specific fuzz patterns & configs.
}

Expand Down
31 changes: 31 additions & 0 deletions checks/raw/fuzzing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,37 @@ func Test_fuzzFileAndFuncMatchPattern(t *testing.T) {
fileContent: `func main (t *testing.T)`,
wantErr: true,
},
{
name: "cpp fuzz func test1",
expectedFileMatch: true,
expectedFuncMatch: true,
lang: clients.LanguageName("c++"),
fileName: "fuzz_test1.cpp",
fileContent: `extern "C" int LLVMFuzzerTestOneInputProperty
(const uint8_t * data, size_t size)`,
wantErr: false,
},
{
name: "cpp fuzz func test2",
expectedFileMatch: true,
expectedFuncMatch: true,
lang: clients.LanguageName("c++"),
fileName: "fuzz_test2_foo.cpp",
fileContent: `
extern void realloc_fuzz_test(void);
extern int MemcmpFuzzTest(void);
`,
wantErr: false,
},
{
name: "cpp fuzz func test3",
expectedFileMatch: false,
expectedFuncMatch: false,
lang: clients.LanguageName("c++"),
fileName: "notAFuzzFile_1.cpp",
fileContent: `extern char* TestProperty1 (void);`,
wantErr: true,
},
{
name: "Test_fuzzFuncRegex not a support language",
expectedFileMatch: false,
Expand Down
29 changes: 29 additions & 0 deletions clients/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type LanguageName string

// TODO: retrieve all languages supported by GitHub, or add one manually if needed.
// Currently, this is still an incomplete list of languages.
// For the complete language list, see:
// https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
const (
// Go: https://go.dev/
Go LanguageName = "go"
Expand Down Expand Up @@ -71,6 +73,33 @@ const (
// Dockerfile: https://docs.docker.com/engine/reference/builder/
Dockerfile LanguageName = "dockerfile"

// HTML: https://www.w3schools.com/html/
HTML LanguageName = "html"

// Shell: https://www.shellscript.sh/
Shell LanguageName = "shell"

// Nix: https://nixos.wiki/wiki/Nix_Expression_Language
Nix LanguageName = "nix"

// Dart: https://dart.dev/
Dart LanguageName = "dart"

// Groovy: https://groovy-lang.org/
Groovy LanguageName = "groovy"

// Perl: https://www.perl.org/
Perk LanguageName = "perl"

// Objective-C: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC
ObjectiveC LanguageName = "objective-c"

// R: https://www.r-project.org/
R LanguageName = "r"

// MATLAB: https://www.mathworks.com/
MATLAB LanguageName = "matlab"

// Other indicates other languages not listed by the GitHub API.
Other LanguageName = "other"

Expand Down
2 changes: 1 addition & 1 deletion docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ This check tries to determine if the project uses
[fuzzing](https://owasp.org/www-community/Fuzzing) by checking:
1. if the repository name is included in the [OSS-Fuzz](https://github.com/google/oss-fuzz) project list;
2. if [ClusterFuzzLite](https://google.github.io/clusterfuzzlite/) is deployed in the repository;
3. if there are user-defined language-specified fuzzing functions (currently only supports [Go fuzzing](https://go.dev/doc/fuzz/)) in the repository.
3. if there are user-defined language-specified fuzzing functions (currently supports [Go Fuzzing](https://go.dev/doc/fuzz/)) and [C++ Fuzz Test](https://help.code-intelligence.com/create-a-c-fuzz-test) in the repository.

Fuzzing, or fuzz testing, is the practice of feeding unexpected or random data
into a program to expose bugs. Regular fuzzing is important to detect
Expand Down
2 changes: 1 addition & 1 deletion docs/checks/internal/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ checks:
[fuzzing](https://owasp.org/www-community/Fuzzing) by checking:
1. if the repository name is included in the [OSS-Fuzz](https://github.com/google/oss-fuzz) project list;
2. if [ClusterFuzzLite](https://google.github.io/clusterfuzzlite/) is deployed in the repository;
3. if there are user-defined language-specified fuzzing functions (currently only supports [Go fuzzing](https://go.dev/doc/fuzz/)) in the repository.
3. if there are user-defined language-specified fuzzing functions (currently supports [Go Fuzzing](https://go.dev/doc/fuzz/)) and [C++ Fuzz Test](https://help.code-intelligence.com/create-a-c-fuzz-test) in the repository.
Fuzzing, or fuzz testing, is the practice of feeding unexpected or random data
into a program to expose bugs. Regular fuzzing is important to detect
Expand Down

0 comments on commit 9a0f160

Please sign in to comment.