Oh now I see what you mean. Preamble is of gcov_preamble type. I'll change sizeof( gcov_preamble ) to sizeof( preamble ) to make that easier to follow.
-----Original Message----- From: Gedare Bloom <ged...@rtems.org> Sent: Thursday, August 12, 2021 12:39 PM To: Ryan Long <ryan.l...@oarcorp.com> Cc: devel@rtems.org Subject: Re: [PATCH] GcovData.cc: Fix out-of-bounds access errors On Thu, Aug 12, 2021 at 7:54 AM Ryan Long <ryan.l...@oarcorp.com> wrote: > > Would you need to check if length < sizeof(gcov_preamble) since length is > assigned that value? > No, but my question is about 'preamble'. If there's a difference between 'preamble' and 'gcov_preamble', then that should be checked. If they should be the same, that should be asserted, probably. > -----Original Message----- > From: Gedare Bloom <ged...@rtems.org> > Sent: Wednesday, August 11, 2021 11:13 AM > To: Ryan Long <ryan.l...@oarcorp.com> > Cc: devel@rtems.org > Subject: Re: [PATCH] GcovData.cc: Fix out-of-bounds access errors > > On Wed, Aug 11, 2021 at 8:06 AM Ryan Long <ryan.l...@oarcorp.com> wrote: > > > > 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 ); > Does something ensure that sizeof(preamble) < length? > > regardless, the patch looks like an improvement, go ahead. > > > + if ( gcovFile.gcount() != length ) { > > std::cerr << "Error while reading file preamble" << std::endl; > > return -1; > > } > > -- > > 1.8.3.1 > > > > _______________________________________________ > > devel mailing list > > devel@rtems.org > > http://lists.rtems.org/mailman/listinfo/devel _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel