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;

Binary file not shown.

View File

@ -113,6 +113,11 @@ RUN: FileCheck --check-prefix=ELEMENT-TYPE %s
ELEMENT-TYPE: Invalid type
RUN: not llvm-dis -disable-output %p/Inputs/invalid-cast.bc 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-CAST %s
INVALID-CAST: Invalid cast
RUN: not llvm-dis -disable-output %p/Inputs/invalid-array-op-not-2nd-to-last.bc 2>&1 | \
RUN: FileCheck --check-prefix=ARRAY-NOT-2LAST %s