From 9a0f160dc39b50b0810c07369ead27417492f5dd Mon Sep 17 00:00:00 2001 From: Aiden Wang Date: Thu, 23 Jun 2022 00:04:06 +0000 Subject: [PATCH] add cpp fuzz func support && unit tests, add more const languages --- checks/raw/fuzzing.go | 10 ++++++++++ checks/raw/fuzzing_test.go | 31 +++++++++++++++++++++++++++++++ clients/languages.go | 29 +++++++++++++++++++++++++++++ docs/checks.md | 2 +- docs/checks/internal/checks.yaml | 2 +- 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/checks/raw/fuzzing.go b/checks/raw/fuzzing.go index 4d8cb3636d7..6e31d1f3594 100644 --- a/checks/raw/fuzzing.go +++ b/checks/raw/fuzzing.go @@ -30,6 +30,7 @@ const ( fuzzerOSSFuzz = "OSSFuzz" fuzzerClusterFuzzLite = "ClusterFuzzLite" fuzzerBuiltInGo = "GoBuiltInFuzzer" + fuzzerBuiltInCpp = "CppBuiltInFuzzer" // TODO: add more fuzzing check supports. ) @@ -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. } diff --git a/checks/raw/fuzzing_test.go b/checks/raw/fuzzing_test.go index 65c811c8b9b..adf210ffe7d 100644 --- a/checks/raw/fuzzing_test.go +++ b/checks/raw/fuzzing_test.go @@ -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, diff --git a/clients/languages.go b/clients/languages.go index 417c67084c9..858a9638a29 100644 --- a/clients/languages.go +++ b/clients/languages.go @@ -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" @@ -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" diff --git a/docs/checks.md b/docs/checks.md index 70696ed1517..c64c073a22f 100644 --- a/docs/checks.md +++ b/docs/checks.md @@ -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 diff --git a/docs/checks/internal/checks.yaml b/docs/checks/internal/checks.yaml index f15bd2f9e93..af2dd09277d 100644 --- a/docs/checks/internal/checks.yaml +++ b/docs/checks/internal/checks.yaml @@ -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