Skip to content

Commit 9af467e

Browse files
ljmf00dwblaikie
authored andcommitted
[Tools] Add a fuzzing tool to help fuzzing D demangler
This patch adds a fuzzing helper tool for D demangler by feeding the demangler API with pseudo-random null terminated strings with the help of libfuzzer heuristics. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D111432
1 parent 3c47c5c commit 9af467e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(LLVM_LINK_COMPONENTS
2+
Demangle
3+
FuzzMutate
4+
Support
5+
)
6+
7+
add_llvm_fuzzer(llvm-dlang-demangle-fuzzer
8+
llvm-dlang-demangle-fuzzer.cpp
9+
DUMMY_MAIN DummyDemanglerFuzzer.cpp
10+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- DummyDemanglerFuzzer.cpp - Entry point to sanity check the fuzzer -===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Implementation of main so we can build and test without linking libFuzzer.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "llvm/FuzzMutate/FuzzerCLI.h"
14+
15+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
16+
int main(int argc, char *argv[]) {
17+
return llvm::runFuzzerOnInputs(argc, argv, LLVMFuzzerTestOneInput);
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===--- llvm-dlang-demangle-fuzzer.cpp - Fuzzer for the DLang Demangler --===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/Demangle/Demangle.h"
10+
#include <cstdint>
11+
#include <cstdlib>
12+
#include <string>
13+
14+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
15+
std::string NullTerminatedString((const char *)Data, Size);
16+
char *Demangled = llvm::dlangDemangle(NullTerminatedString.c_str());
17+
std::free(Demangled);
18+
return 0;
19+
}

0 commit comments

Comments
 (0)