Make sure Op->getType() is a PointerType before we cast<> it.
authorFilipe Cabecinhas <me@filcab.net>
Thu, 30 Apr 2015 01:13:31 +0000 (01:13 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Thu, 30 Apr 2015 01:13:31 +0000 (01:13 +0000)
Bug found with AFL fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236193 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
test/Bitcode/Inputs/invalid-load-pointer-type.bc [new file with mode: 0644]
test/Bitcode/invalid.test

index 7778125e2d482226a37034e86d63836b79bcc8b6..456df6dab8e410788b0aa9c0d38b92921c1440b2 100644 (file)
@@ -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<PointerType>(Op->getType()))
+        return Error("Load operand is not a pointer type");
       if (!Ty)
         Ty = cast<PointerType>(Op->getType())->getElementType();
       else if (Ty != cast<PointerType>(Op->getType())->getElementType())
diff --git a/test/Bitcode/Inputs/invalid-load-pointer-type.bc b/test/Bitcode/Inputs/invalid-load-pointer-type.bc
new file mode 100644 (file)
index 0000000..b6a56c5
Binary files /dev/null and b/test/Bitcode/Inputs/invalid-load-pointer-type.bc differ
index 077f35151286d026e2c1b6f904ffdb81903de9dc..4aff5c0050117193b9bfb2056b60085aa78c96ac 100644 (file)
@@ -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