[PATCH] D60771: llvm-undname: Add a -raw-input flag to pass a raw buffer to microsoftDemangle
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 05:34:57 PDT 2019
thakis created this revision.
thakis added a reviewer: hans.
Herald added a subscriber: erik.pilkington.
Herald added a project: LLVM.
The default handling splits input into lines. Since
llvm-microsoft-demangle-fuzzer doesn't do this, oss-fuzz produces inputs
that only trigger crashes if the input isn't split into lines. This adds
a hidden flag -raw-input which passes input to microsoftDemangle() in
the same way the fuzzer does, for reproducing oss-fuzz reports.
Also change llvm-undname to have a non-0 exit code for invalid symbols.
https://reviews.llvm.org/D60771
Files:
llvm/tools/llvm-undname/llvm-undname.cpp
Index: llvm/tools/llvm-undname/llvm-undname.cpp
===================================================================
--- llvm/tools/llvm-undname/llvm-undname.cpp
+++ llvm/tools/llvm-undname/llvm-undname.cpp
@@ -15,7 +15,9 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
@@ -29,10 +31,12 @@
cl::opt<bool> DumpBackReferences("backrefs", cl::Optional,
cl::desc("dump backreferences"), cl::Hidden,
cl::init(false));
+cl::opt<std::string> RawInput("raw-input", cl::Optional,
+ cl::desc("for fuzzer data"), cl::Hidden);
cl::list<std::string> Symbols(cl::Positional, cl::desc("<input symbols>"),
cl::ZeroOrMore);
-static void msDemangle(const std::string &S) {
+static bool msDemangle(const std::string &S) {
int Status;
MSDemangleFlags Flags = MSDF_None;
if (DumpBackReferences)
@@ -47,6 +51,7 @@
WithColor::error() << "Invalid mangled name\n";
}
std::free(ResultBuf);
+ return Status == llvm::demangle_success;
}
int main(int argc, char **argv) {
@@ -54,6 +59,18 @@
cl::ParseCommandLineOptions(argc, argv, "llvm-undname\n");
+ if (!RawInput.empty()) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
+ MemoryBuffer::getFileOrSTDIN(RawInput);
+ if (std::error_code EC = FileOrErr.getError()) {
+ WithColor::error() << "Could not open input file \'" << RawInput
+ << "\': " << EC.message() << '\n';
+ return 1;
+ }
+ return msDemangle(FileOrErr->get()->getBuffer()) ? 0 : 1;
+ }
+
+ bool Success = true;
if (Symbols.empty()) {
while (true) {
std::string LineStr;
@@ -74,17 +91,19 @@
outs() << Line << "\n";
outs().flush();
}
- msDemangle(Line);
+ if (!msDemangle(Line))
+ Success = false;
outs() << "\n";
}
} else {
for (StringRef S : Symbols) {
outs() << S << "\n";
outs().flush();
- msDemangle(S);
+ if (!msDemangle(S))
+ Success = false;
outs() << "\n";
}
}
- return 0;
+ return Success ? 0 : 1;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60771.195357.patch
Type: text/x-patch
Size: 2432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190416/4180d141/attachment.bin>
More information about the llvm-commits
mailing list