From 3b821159da170b233a3ba8c12ce47ee6662946f0 Mon Sep 17 00:00:00 2001 From: Filipe Cabecinhas Date: Sat, 30 May 2015 00:17:20 +0000 Subject: [PATCH] [BitcodeReader] Change an assert to a call to a call to Error() 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 | 4 ++-- .../invalid-metadata-not-followed-named-node.bc | Bin 0 -> 878 bytes test/Bitcode/invalid.test | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/Bitcode/Inputs/invalid-metadata-not-followed-named-node.bc diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 441a4c76344..4044ac80f20 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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 index 0000000000000000000000000000000000000000..42a2c3e65fecb9d56daa43ef548231050f386510 GIT binary patch literal 878 zcmZ>AK5$Qwhk+rFfq{X$Nr8b0NDBcmd!zD1#}h1`Yyw7>lNeigR9QJB}F$U_-75k}h%XN#7@Jx&eml@;v8GYWa0 zG4Q_?;QP|RXUyXycj%z(xrH)m2CQIZ&C+L>ZBIDc_AuK5%_vl0U;vpXwn3rS#U+?k zM@f^%x#tgFm|LGBAaa0SkGug9iEd#QM;(xUP_htFW-u`Z(whaFLBt_o`rrd46i`&M2Z%w<7A4 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 -- 2.34.1