From: Filipe Cabecinhas Date: Thu, 30 Apr 2015 01:13:31 +0000 (+0000) Subject: Make sure Op->getType() is a PointerType before we cast<> it. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9a19e56306a4fd2a08e89d51fad3fb6abb8a3c64;p=platform%2Fupstream%2Fllvm.git Make sure Op->getType() is a PointerType before we cast<> it. Bug found with AFL fuzz. llvm-svn: 236193 --- diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 7778125..456df6d 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4065,6 +4065,8 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { Type *Ty = nullptr; if (OpNum + 3 == Record.size()) Ty = getTypeByID(Record[OpNum++]); + if (!isa(Op->getType())) + return Error("Load operand is not a pointer type"); if (!Ty) Ty = cast(Op->getType())->getElementType(); else if (Ty != cast(Op->getType())->getElementType()) diff --git a/llvm/test/Bitcode/Inputs/invalid-load-pointer-type.bc b/llvm/test/Bitcode/Inputs/invalid-load-pointer-type.bc new file mode 100644 index 0000000..b6a56c5 Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-load-pointer-type.bc differ diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index 077f351..4aff5c00 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -117,3 +117,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-too-big-fwdref.bc 2>&1 | \ RUN: FileCheck --check-prefix=HUGE-FWDREF %s HUGE-FWDREF: Invalid record + +RUN: not llvm-dis -disable-output %p/Inputs/invalid-load-pointer-type.bc 2>&1 | \ +RUN: FileCheck --check-prefix=LOAD-BAD-TYPE %s + +LOAD-BAD-TYPE: Load operand is not a pointer type