Make sure the CastInst is valid before trying to create it

Bug found with afl-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249396 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Filipe Cabecinhas
2015-10-06 12:37:54 +00:00
parent b0c38394ff
commit fdb28cdd8b
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;