[llvm] r238633 - [BitcodeReader] Change an assert to a call to a call to Error()

Filipe Cabecinhas me at filcab.net
Fri May 29 17:17:21 PDT 2015


Author: filcab
Date: Fri May 29 19:17:20 2015
New Revision: 238633

URL: http://llvm.org/viewvc/llvm-project?rev=238633&view=rev
Log:
[BitcodeReader] Change an assert to a call to a call to Error()

It's reachable from user input.

Bug found with AFL fuzz.

Added:
    llvm/trunk/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.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=238633&r1=238632&r2=238633&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri May 29 19:17:20 2015
@@ -1634,9 +1634,9 @@ std::error_code BitcodeReader::ParseMeta
       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();

Added: llvm/trunk/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc?rev=238633&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc (added) and llvm/trunk/test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc Fri May 29 19:17:20 2015 differ

Modified: llvm/trunk/test/Bitcode/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid.test?rev=238633&r1=238632&r2=238633&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/invalid.test (original)
+++ llvm/trunk/test/Bitcode/invalid.test Fri May 29 19:17:20 2015
@@ -187,3 +187,8 @@ RUN: not llvm-dis -disable-output %p/Inp
 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





More information about the llvm-commits mailing list