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-as/llvm-as.cpp | |
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-as/llvm-as.cpp')
-rw-r--r-- | llvm/tools/llvm-as/llvm-as.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp index c6b3f934202..4455d24fb60 100644 --- a/llvm/tools/llvm-as/llvm-as.cpp +++ b/llvm/tools/llvm-as/llvm-as.cpp @@ -62,14 +62,8 @@ static void WriteOutputFile(const Module *M) { 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"; } } |