[llvm] r237051 - Fix input validation issues in llvm-as/llvm-dis
Alexey Samsonov
vonosmas at gmail.com
Mon May 11 14:20:21 PDT 2015
Author: samsonov
Date: Mon May 11 16:20:20 2015
New Revision: 237051
URL: http://llvm.org/viewvc/llvm-project?rev=237051&view=rev
Log:
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
Modified:
llvm/trunk/tools/llvm-as/llvm-as.cpp
llvm/trunk/tools/llvm-dis/llvm-dis.cpp
Modified: llvm/trunk/tools/llvm-as/llvm-as.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-as/llvm-as.cpp?rev=237051&r1=237050&r2=237051&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-as/llvm-as.cpp (original)
+++ llvm/trunk/tools/llvm-as/llvm-as.cpp Mon May 11 16:20:20 2015
@@ -62,14 +62,8 @@ static void WriteOutputFile(const Module
if (InputFilename == "-") {
OutputFilename = "-";
} else {
- std::string IFN = InputFilename;
- int Len = IFN.length();
- if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
- // Source ends in .ll
- OutputFilename = std::string(IFN.begin(), IFN.end()-3);
- } else {
- OutputFilename = IFN; // Append a .bc to it
- }
+ StringRef IFN = InputFilename;
+ OutputFilename = (IFN.endswith(".ll") ? IFN.drop_back(3) : IFN).str();
OutputFilename += ".bc";
}
}
Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=237051&r1=237050&r2=237051&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Mon May 11 16:20:20 2015
@@ -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";
}
}
More information about the llvm-commits
mailing list