From: Filipe Cabecinhas Date: Tue, 6 Oct 2015 12:37:54 +0000 (+0000) Subject: Make sure the CastInst is valid before trying to create it X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fdb28cdd8b6bfe412382225adcb9cac0c3a8467b;p=oota-llvm.git 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 --- diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 2893eaef0fb..ce6790be713 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/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; diff --git a/test/Bitcode/Inputs/invalid-cast.bc b/test/Bitcode/Inputs/invalid-cast.bc new file mode 100644 index 00000000000..a8b82f3e286 Binary files /dev/null and b/test/Bitcode/Inputs/invalid-cast.bc differ diff --git a/test/Bitcode/invalid.test b/test/Bitcode/invalid.test index 0aab553bb61..69104046df2 100644 --- a/test/Bitcode/invalid.test +++ b/test/Bitcode/invalid.test @@ -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