[llvm] r271243 - [llvm-pdbdump-fuzzer] Add a fuzzer for llvm-pdbdump
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Tue May 31 08:15:44 PDT 2016
Cool to see a fuzzer for this :) (thought you had/were using one, going by
the fixes you've been checking in)
Idle thoughts, none necessary:
On Mon, May 30, 2016 at 6:24 PM, David Majnemer via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: majnemer
> Date: Mon May 30 20:24:40 2016
> New Revision: 271243
>
> URL: http://llvm.org/viewvc/llvm-project?rev=271243&view=rev
> Log:
> [llvm-pdbdump-fuzzer] Add a fuzzer for llvm-pdbdump
>
> Added:
> llvm/trunk/tools/llvm-pdbdump/fuzzer/
> llvm/trunk/tools/llvm-pdbdump/fuzzer/CMakeLists.txt
> llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp
> Modified:
> llvm/trunk/tools/llvm-pdbdump/CMakeLists.txt
>
> Modified: llvm/trunk/tools/llvm-pdbdump/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/CMakeLists.txt?rev=271243&r1=271242&r2=271243&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbdump/CMakeLists.txt (original)
> +++ llvm/trunk/tools/llvm-pdbdump/CMakeLists.txt Mon May 30 20:24:40 2016
> @@ -18,3 +18,7 @@ add_llvm_tool(llvm-pdbdump
> TypedefDumper.cpp
> VariableDumper.cpp
> )
> +
> +if(LLVM_USE_SANITIZE_COVERAGE)
> + add_subdirectory(fuzzer)
> +endif()
>
> Added: llvm/trunk/tools/llvm-pdbdump/fuzzer/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/fuzzer/CMakeLists.txt?rev=271243&view=auto
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbdump/fuzzer/CMakeLists.txt (added)
> +++ llvm/trunk/tools/llvm-pdbdump/fuzzer/CMakeLists.txt Mon May 30
> 20:24:40 2016
> @@ -0,0 +1,15 @@
> +set(LLVM_LINK_COMPONENTS
> + DebugInfoCodeView
> + DebugInfoPDB
> + Object
> + Support
> + )
> +
> +add_llvm_executable(llvm-pdbdump-fuzzer
> + EXCLUDE_FROM_ALL
> + llvm-pdbdump-fuzzer.cpp
> + )
> +
> +target_link_libraries(llvm-pdbdump-fuzzer
> + LLVMFuzzer
> + )
>
> Added: llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp?rev=271243&view=auto
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp (added)
> +++ llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp Mon May
> 30 20:24:40 2016
> @@ -0,0 +1,77 @@
> +//===-- llvm-pdbdump-fuzzer.cpp - Fuzz the llvm-pdbdump tool
> --------------===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +///
> +/// \file
> +/// \brief This file implements a function that runs llvm-pdbdump
> +/// on a single input. This function is then linked into the Fuzzer
> library.
> +///
>
> +//===----------------------------------------------------------------------===//
> +#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
> +#include "llvm/DebugInfo/CodeView/TypeDumper.h"
> +#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
> +#include "llvm/DebugInfo/PDB/Raw/ModStream.h"
> +#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
> +#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
> +#include "llvm/Support/MemoryBuffer.h"
> +#include "llvm/Support/ScopedPrinter.h"
> +
> +using namespace llvm;
> +
> +extern "C" void LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
> + std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
> + StringRef((const char *)data, size), "", false);
> +
> + ScopedPrinter P(nulls());
> + codeview::CVTypeDumper TD(P, false);
> +
> + std::unique_ptr<pdb::PDBFile> File(new pdb::PDBFile(std::move(Buff)));
>
^ llvm::make_unique? Actually, this could just be a local stack variable,
maybe? ("pdb::PDBFile File(std::move(Buf));")
> + if (auto E = File->parseFileHeaders()) {
> + consumeError(std::move(E));
> + return;
>
If you indirect through another function, you could collapse these checks a
bit, which might be nice given the repetition:
if (auto E = ... )
return E;
repeat, then have the LLVMFUzzerTestOneInput function call this other
function and consumeError its result.
Alternatively you could use the somewhat less common "return with a void
expression" (assuming consumeError is void returning, I haven't checked) to
write these as:
if (auto E = ...)
return consumeError(std::move(E));
> + }
> + if (auto E = File->parseStreamData()) {
> + consumeError(std::move(E));
> + return;
> + }
> +
> + auto DbiS = File->getPDBDbiStream();
> + if (auto E = DbiS.takeError()) {
> + consumeError(std::move(E));
> + return;
> + }
> + auto TpiS = File->getPDBTpiStream();
> + if (auto E = TpiS.takeError()) {
> + consumeError(std::move(E));
> + return;
> + }
> + auto IpiS = File->getPDBIpiStream();
> + if (auto E = IpiS.takeError()) {
> + consumeError(std::move(E));
> + return;
> + }
> + auto InfoS = File->getPDBInfoStream();
> + if (auto E = InfoS.takeError()) {
> + consumeError(std::move(E));
> + return;
> + }
> + pdb::DbiStream &DS = DbiS.get();
> +
> + for (auto &Modi : DS.modules()) {
> + pdb::ModStream ModS(*File, Modi.Info);
> + if (auto E = ModS.reload()) {
> + consumeError(std::move(E));
> + return;
> + }
> + codeview::CVSymbolDumper SD(P, TD, nullptr, false);
> + bool HadError = false;
> + for (auto &S : ModS.symbols(&HadError)) {
> + SD.dump(S);
> + }
Don't usually bother with {} on a single line block.
>
+ }
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160531/95366079/attachment.html>
More information about the llvm-commits
mailing list