[BitcodeReader] Make sure the type of the inserted value matches the type of the...
authorFilipe Cabecinhas <me@filcab.net>
Mon, 18 May 2015 22:27:11 +0000 (22:27 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Mon, 18 May 2015 22:27:11 +0000 (22:27 +0000)
Bug found with AFL-fuzz.

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

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

index 86c61bdf66b33035527114c225588106b25de8d4..70b681000a719112e9edb425ddeee44667ebf633 100644 (file)
@@ -3644,6 +3644,9 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
           CurTy = CurTy->subtypes()[0];
       }
 
+      if (CurTy != Val->getType())
+        return Error("Inserted value type doesn't match aggregate type");
+
       I = InsertValueInst::Create(Agg, Val, INSERTVALIdx);
       InstructionList.push_back(I);
       break;
diff --git a/test/Bitcode/Inputs/invalid-inserted-value-type-mismatch.bc b/test/Bitcode/Inputs/invalid-inserted-value-type-mismatch.bc
new file mode 100644 (file)
index 0000000..81333cd
Binary files /dev/null and b/test/Bitcode/Inputs/invalid-inserted-value-type-mismatch.bc differ
index 7dd97a4f49a8b2a4db5bc9142cf2f26bf7db8598..921d4e62c04918933098047b3eece52a4e82c539 100644 (file)
@@ -142,3 +142,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-load-ptr-type.bc 2>&1 | \
 RUN:   FileCheck --check-prefix=BAD-LOAD-PTR-TYPE %s
 
 BAD-LOAD-PTR-TYPE: Cannot load/store from pointer
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-inserted-value-type-mismatch.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=INSERT-TYPE-MISMATCH %s
+
+INSERT-TYPE-MISMATCH: Inserted value type doesn't match aggregate type