llvm.org GIT mirror llvm / 4e5be5a
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237051 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 4 years ago
2 changed file(s) with 10 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
6161 if (InputFilename == "-") {
6262 OutputFilename = "-";
6363 } else {
64 std::string IFN = InputFilename;
65 int Len = IFN.length();
66 if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
67 // Source ends in .ll
68 OutputFilename = std::string(IFN.begin(), IFN.end()-3);
69 } else {
70 OutputFilename = IFN; // Append a .bc to it
71 }
64 StringRef IFN = InputFilename;
65 OutputFilename = (IFN.endswith(".ll") ? IFN.drop_back(3) : IFN).str();
7266 OutputFilename += ".bc";
7367 }
7468 }
7979 if (!V.getType()->isVoidTy()) {
8080 OS.PadToColumn(50);
8181 Padded = true;
82 OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]"; // Output # uses and type
82 // Output # uses and type
83 OS << "; [#uses=" << V.getNumUses() << " type=" << *V.getType() << "]";
8384 }
8485 if (const Instruction *I = dyn_cast(&V)) {
8586 if (const DebugLoc &DL = I->getDebugLoc()) {
157158 getStreamedBitcodeModule(DisplayFilename, Streamer, Context);
158159 M = std::move(*MOrErr);
159160 M->materializeAllPermanently();
161 } else {
162 errs() << argv[0] << ": " << ErrorMessage << '\n';
163 return 1;
160164 }
161165
162166 // Just use stdout. We won't actually print anything on it.
167171 if (InputFilename == "-") {
168172 OutputFilename = "-";
169173 } else {
170 const std::string &IFN = InputFilename;
171 int Len = IFN.length();
172 // If the source ends in .bc, strip it off.
173 if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c')
174 OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll";
175 else
176 OutputFilename = IFN+".ll";
174 StringRef IFN = InputFilename;
175 OutputFilename = (IFN.endswith(".bc") ? IFN.drop_back(3) : IFN).str();
176 OutputFilename += ".ll";
177177 }
178178 }
179179