[llvm] r194639 - llvm-cov: Slightly improved error checking.

Yuchen Wu yuchenericwu at hotmail.com
Wed Nov 13 16:38:41 PST 2013


Author: ywu
Date: Wed Nov 13 18:38:41 2013
New Revision: 194639

URL: http://llvm.org/viewvc/llvm-project?rev=194639&view=rev
Log:
llvm-cov: Slightly improved error checking.

- readInt() should check all 4 bytes can be read, not just 1.
- In the event of false data in the gcno file, it was possible to index
  into a non-existent index of SmallVector, causing assertion error.

Modified:
    llvm/trunk/include/llvm/Support/GCOV.h
    llvm/trunk/lib/IR/GCOV.cpp

Modified: llvm/trunk/include/llvm/Support/GCOV.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GCOV.h?rev=194639&r1=194638&r2=194639&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GCOV.h (original)
+++ llvm/trunk/include/llvm/Support/GCOV.h Wed Nov 13 18:38:41 2013
@@ -152,11 +152,11 @@ public:
   }
 
   bool readInt(uint32_t &Val) {
-    StringRef Str = Buffer->getBuffer().slice(Cursor, Cursor+4);
-    if (Str.empty()) {
+    if (Buffer->getBuffer().size() < Cursor+4) {
       errs() << "Unexpected end of memory buffer: " << Cursor+4 << ".\n";
       return false;
     }
+    StringRef Str = Buffer->getBuffer().slice(Cursor, Cursor+4);
     Cursor += 4;
     Val = *(const uint32_t *)(Str.data());
     return true;

Modified: llvm/trunk/lib/IR/GCOV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=194639&r1=194638&r2=194639&view=diff
==============================================================================
--- llvm/trunk/lib/IR/GCOV.cpp (original)
+++ llvm/trunk/lib/IR/GCOV.cpp Wed Nov 13 18:38:41 2013
@@ -135,6 +135,10 @@ bool GCOVFunction::read(GCOVBuffer &Buff
     // This for loop adds the counts for each block. A second nested loop is
     // required to combine the edge counts that are contained in the GCDA file.
     for (uint32_t Line = 0; Count > 0; ++Line) {
+      if (Line >= Blocks.size()) {
+        errs() << "Unexpected number of edges.\n";
+        return false;
+      }
       GCOVBlock &Block = *Blocks[Line];
       for (size_t Edge = 0, End = Block.getNumEdges(); Edge < End; ++Edge) {
         if (Count == 0) {





More information about the llvm-commits mailing list