Don't overflow GCTable
authorFilipe Cabecinhas <me@filcab.net>
Thu, 30 Apr 2015 04:09:41 +0000 (04:09 +0000)
committerFilipe Cabecinhas <me@filcab.net>
Thu, 30 Apr 2015 04:09:41 +0000 (04:09 +0000)
Summary: Bug found with AFL fuzz.

Reviewers: rafael, dexonsmith

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9361

llvm-svn: 236200

llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/test/Bitcode/Inputs/invalid-GCTable-overflow.bc [new file with mode: 0644]
llvm/test/Bitcode/invalid.test

index 456df6d..aed1196 100644 (file)
@@ -2992,7 +2992,7 @@ std::error_code BitcodeReader::ParseModule(bool Resume,
         // FIXME: Change to an error if non-default in 4.0.
         Func->setVisibility(GetDecodedVisibility(Record[7]));
       if (Record.size() > 8 && Record[8]) {
-        if (Record[8]-1 > GCTable.size())
+        if (Record[8]-1 >= GCTable.size())
           return Error("Invalid ID");
         Func->setGC(GCTable[Record[8]-1].c_str());
       }
diff --git a/llvm/test/Bitcode/Inputs/invalid-GCTable-overflow.bc b/llvm/test/Bitcode/Inputs/invalid-GCTable-overflow.bc
new file mode 100644 (file)
index 0000000..a9e9c52
Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-GCTable-overflow.bc differ
index 4aff5c0..2fe7798 100644 (file)
@@ -122,3 +122,8 @@ 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
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-GCTable-overflow.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=GCTABLE-OFLOW %s
+
+GCTABLE-OFLOW: Invalid ID