diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2015-05-11 21:20:20 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2015-05-11 21:20:20 +0000 |
commit | d92350878221f10923fe1572ba5192b67a19c8de (patch) | |
tree | 7713fcc6301992a2b47b7496fc780d11261e54dc /llvm/tools/llvm-dis | |
parent | 225262562f803997496b394e3b69714cc9ac7dd8 (diff) | |
download | bcm5719-llvm-d92350878221f10923fe1572ba5192b67a19c8de.tar.gz bcm5719-llvm-d92350878221f10923fe1572ba5192b67a19c8de.zip |
Fix input validation issues in llvm-as/llvm-dis
Summary:
1. llvm-as/llvm-dis tools do not check for input filename length.
2. llvm-dis does not verify the `Streamer` variable against `nullptr` properly, so the `M` variable could be uninitialized (e.g. if the input file does not exist) leading to null dref.
Patch by Lenar Safin!
Reviewers: samsonov
Reviewed By: samsonov
Subscribers: samsonov, llvm-commits
Differential Revision: http://reviews.llvm.org/D9584
llvm-svn: 237051
Diffstat (limited to 'llvm/tools/llvm-dis')
-rw-r--r-- | llvm/tools/llvm-dis/llvm-dis.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp index 5f5d634000c..26f14b9b1a2 100644 --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -80,7 +80,8 @@ public: if (!V.getType()->isVoidTy()) { OS.PadToColumn(50); Padded = true; - OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]"; // Output # uses and type + // Output # uses and type + OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]"; } if (const Instruction *I = dyn_cast<Instruction>(&V)) { if (const DebugLoc &DL = I->getDebugLoc()) { @@ -158,6 +159,9 @@ int main(int argc, char **argv) { getStreamedBitcodeModule(DisplayFilename, Streamer, Context); M = std::move(*MOrErr); M->materializeAllPermanently(); + } else { + errs() << argv[0] << ": " << ErrorMessage << '\n'; + return 1; } // Just use stdout. We won't actually print anything on it. @@ -168,13 +172,9 @@ int main(int argc, char **argv) { if (InputFilename == "-") { OutputFilename = "-"; } else { - const std::string &IFN = InputFilename; - int Len = IFN.length(); - // If the source ends in .bc, strip it off. - if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') - OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll"; - else - OutputFilename = IFN+".ll"; + StringRef IFN = InputFilename; + OutputFilename = (IFN.endswith(".bc") ? IFN.drop_back(3) : IFN).str(); + OutputFilename += ".ll"; } } |