[rtems-tools commit] GcovData.cc: Fix out-of-bounds access errors

Joel Sherrill joel at rtems.org
Fri Aug 20 17:46:59 UTC 2021


Module:    rtems-tools
Branch:    master
Commit:    0ab060ff2c52159d2fd7aba7ea58454ee7491973
Changeset: http://git.rtems.org/rtems-tools/commit/?id=0ab060ff2c52159d2fd7aba7ea58454ee7491973

Author:    Ryan Long <ryan.long at oarcorp.com>
Date:      Tue Aug 17 10:11:48 2021 -0400

GcovData.cc: Fix out-of-bounds access errors

Adjusted number of bytes to be read, removed length variable

CID 1506208: Out-of-bounds access
CID 1506209: Out-of-bounds access

Closes #4485

---

 tester/covoar/GcovData.cc | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tester/covoar/GcovData.cc b/tester/covoar/GcovData.cc
index d4acfa4..44928a9 100644
--- a/tester/covoar/GcovData.cc
+++ b/tester/covoar/GcovData.cc
@@ -130,7 +130,7 @@ namespace Gcov {
     preamble.timestamp = gcnoPreamble.timestamp;
 
     //Write preamble
-    gcdaFile.write( (char *) &preamble , 4 * sizeof( preamble ) );
+    gcdaFile.write( (char *) &preamble , sizeof( preamble ) );
     if ( gcdaFile.fail() ) {
       std::cerr << "Error while writing gcda preamble to a file "
                 << gcdaFileName << std::endl;
@@ -400,13 +400,12 @@ namespace Gcov {
      uint32_t       desiredMagic
   )
   {
-    int length;
-
     rtems::utils::ostream_guard old_state( std::cerr );
 
-    length = sizeof( gcov_preamble );
-    gcovFile.read( (char *) &preamble, 4 * sizeof( gcov_preamble ) );
-    if ( gcovFile.gcount() != 4 * sizeof( gcov_preamble ) ) {
+    // Read the gcov preamble and make sure it is the right length and has the
+    // magic number
+    gcovFile.read( (char *) &preamble, sizeof( gcov_preamble ) );
+    if ( gcovFile.gcount() != sizeof( gcov_preamble ) ) {
       std::cerr << "Error while reading file preamble" << std::endl;
       return -1;
     }
@@ -418,7 +417,7 @@ namespace Gcov {
       return -1;
     }
 
-    return length / 4;
+    return sizeof( gcov_preamble ) / 4;
   }
 
   bool GcovData::readFunctionFrame(



More information about the vc mailing list