Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(811)

Unified Diff: lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp

Issue 1283353002: Fix handling errors in switch instruction by PNaCl bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Use unique_ptr for switch instruction. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/NaCl/Bitcode/pnacl-bcdis/Inputs/bad-switch-case.tbc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
index eab4609770a6d9e917cc42d61747115bd7458c07..cc737c6a5afcd64ebf1a8a066ce39007e7dd243e 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
@@ -1850,7 +1850,8 @@ std::error_code NaClBitcodeReader::ParseFunctionBody(Function *F) {
// TODO(kschimpf): Deal with values that are too large for NumCases.
size_t NumCases = Record[3];
- SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases);
+ std::unique_ptr<SwitchInst> SI(
+ SwitchInst::Create(Cond, Default, NumCases));
size_t CurIdx = 4;
for (size_t i = 0; i != NumCases; ++i) {
@@ -1870,9 +1871,11 @@ std::error_code NaClBitcodeReader::ParseFunctionBody(Function *F) {
APInt CaseValue(ValueBitWidth,
NaClDecodeSignRotatedValue(Record[CurIdx++]));
BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]);
+ if (DestBB == nullptr)
+ return Error(InvalidValue, "Invalid branch in SWITCH case");
SI->addCase(ConstantInt::get(Context, CaseValue), DestBB);
}
- I = SI;
+ I = SI.release();
JF 2015/08/20 16:24:00 At this point it's probably better to do the chang
Karl 2015/08/20 18:30:51 Acknowledged.
break;
}
case naclbitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
« no previous file with comments | « no previous file | test/NaCl/Bitcode/pnacl-bcdis/Inputs/bad-switch-case.tbc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698