[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:23:48 PDT 2016


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)));
> +  if (auto E = File->parseFileHeaders()) {
> +    consumeError(std::move(E));
> +    return;
> +  }
> +  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()) {
>

& I forget the exact API to llvm::Expected, but I suspect you can write
"DBiS->modules()" & skip the DS temp, if you like/prefer, but I can see how
being explicit about the type (in which case I'd probably write it as ... =
*DbiS; (assuming that works...) but, again, different preferences for
what's more readable for sure) might be desired.


> +    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);
> +    }
> +  }
> +}
>
>
> _______________________________________________
> 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/c67cc957/attachment.html>


More information about the llvm-commits mailing list