Make sure the CastInst is valid before trying to create it

Bug found with afl-fuzz.

llvm-svn: 249396
This commit is contained in:
Filipe Cabecinhas
2015-10-06 12:37:54 +00:00
parent 4c33a1af5d
commit b70fd8719e
3 changed files with 9 additions and 1 deletions

View File

@@ -3863,7 +3863,10 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
CurBB->getInstList().push_back(Temp);
}
} else {
I = CastInst::Create((Instruction::CastOps)Opc, Op, ResTy);
auto CastOp = (Instruction::CastOps)Opc;
if (!CastInst::castIsValid(CastOp, Op, ResTy))
return error("Invalid cast");
I = CastInst::Create(CastOp, Op, ResTy);
}
InstructionList.push_back(I);
break;