[llvm] r249396 - Make sure the CastInst is valid before trying to create it
Filipe Cabecinhas via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 05:37:54 PDT 2015
Author: filcab
Date: Tue Oct 6 07:37:54 2015
New Revision: 249396
URL: http://llvm.org/viewvc/llvm-project?rev=249396&view=rev
Log:
Make sure the CastInst is valid before trying to create it
Bug found with afl-fuzz.
Added:
llvm/trunk/test/Bitcode/Inputs/invalid-cast.bc
Modified:
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/test/Bitcode/invalid.test
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=249396&r1=249395&r2=249396&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Oct 6 07:37:54 2015
@@ -3863,7 +3863,10 @@ std::error_code BitcodeReader::parseFunc
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;
Added: llvm/trunk/test/Bitcode/Inputs/invalid-cast.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/invalid-cast.bc?rev=249396&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/Inputs/invalid-cast.bc (added) and llvm/trunk/test/Bitcode/Inputs/invalid-cast.bc Tue Oct 6 07:37:54 2015 differ
Modified: llvm/trunk/test/Bitcode/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid.test?rev=249396&r1=249395&r2=249396&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/invalid.test (original)
+++ llvm/trunk/test/Bitcode/invalid.test Tue Oct 6 07:37:54 2015
@@ -113,6 +113,11 @@ RUN: FileCheck --check-prefix=ELEMENT-
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
More information about the llvm-commits
mailing list