[BitcodeReader] Change an assert to a call to a call to Error()
authorFilipe Cabecinhas <me@filcab.net>
Sat, 30 May 2015 00:17:20 +0000 (00:17 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Sat, 30 May 2015 00:17:20 +0000 (00:17 +0000)
It's reachable from user input.

Bug found with AFL fuzz.

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

lib/Bitcode/Reader/BitcodeReader.cpp
test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc [new file with mode: 0644]
test/Bitcode/invalid.test

index 441a4c76344a69d3246b8a803a2224444cdce157..4044ac80f20330b3de2a72881f5145269b097b5f 100644 (file)
@@ -1634,9 +1634,9 @@ std::error_code BitcodeReader::ParseMetadata() {
       Record.clear();
       Code = Stream.ReadCode();
 
-      // METADATA_NAME is always followed by METADATA_NAMED_NODE.
       unsigned NextBitCode = Stream.readRecord(Code, Record);
-      assert(NextBitCode == bitc::METADATA_NAMED_NODE); (void)NextBitCode;
+      if (NextBitCode != bitc::METADATA_NAMED_NODE)
+        return Error("METADATA_NAME not followed by METADATA_NAMED_NODE");
 
       // Read named metadata elements.
       unsigned Size = Record.size();
diff --git a/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc b/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc
new file mode 100644 (file)
index 0000000..42a2c3e
Binary files /dev/null and b/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc differ
index eb7f979d5745a739912684b4316e013446ace3c2..43f7c77d598a546302389b5cc0ece27919dbb9fe 100644 (file)
@@ -187,3 +187,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-array-operand-encoding.bc 2>
 RUN:   FileCheck --check-prefix=ARRAY-OP-ENC %s
 
 ARRAY-OP-ENC: Array element type has to be an encoding of a type
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-metadata-not-followed-named-node.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=META-NOT-FOLLOWED-BY-NAMED-META %s
+
+META-NOT-FOLLOWED-BY-NAMED-META: METADATA_NAME not followed by METADATA_NAMED_NODE