From b70fd8719e04209827e0ea115965e10225e98f5c Mon Sep 17 00:00:00 2001 From: Filipe Cabecinhas Date: Tue, 6 Oct 2015 12:37:54 +0000 Subject: Make sure the CastInst is valid before trying to create it Bug found with afl-fuzz. llvm-svn: 249396 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 2893eae..ce6790b 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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; -- cgit v1.1