[PATCH] GcovData.cc: Fix out-of-bounds access errors

Ryan Long ryan.long at oarcorp.com
Wed Aug 11 14:05:30 UTC 2021


Adjusted number of bytes to be read

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

Closes #4485
---
 tester/covoar/GcovData.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tester/covoar/GcovData.cc b/tester/covoar/GcovData.cc
index 02e7489..da0cc2a 100644
--- a/tester/covoar/GcovData.cc
+++ b/tester/covoar/GcovData.cc
@@ -129,7 +129,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;
@@ -402,8 +402,8 @@ namespace Gcov {
     int length;
 
     length = sizeof( gcov_preamble );
-    gcovFile.read( (char *) &preamble, 4 * sizeof( gcov_preamble ) );
-    if ( gcovFile.gcount() != 4 * sizeof( gcov_preamble ) ) {
+    gcovFile.read( (char *) &preamble, length );
+    if ( gcovFile.gcount() != length ) {
       std::cerr << "Error while reading file preamble" << std::endl;
       return -1;
     }
-- 
1.8.3.1



More information about the devel mailing list