[Libguestfs] [PATCH v2 1/2] lib: change how hbin sections are read.

Dawid Zamirski dzamirski at datto.com
Wed Feb 15 22:55:14 UTC 2017


On Wed, 2017-02-15 at 22:35 +0000, Richard W.M. Jones wrote:
> On Wed, Feb 15, 2017 at 10:29:41PM +0000, Richard W.M. Jones wrote:
> > Yes, or even how about this (not tried it):
> > 
> > while (off <= h->endpages - 0x1000) {
> >   ...
> > }
> 
> In fact this doesn't work either :-(
> 
> I'll have another look at this tomorrow morning.
> 
> Rich.
> 

Yep, GCC7 complains about that off could overflow over SIZE_MAX when
incremented with 0x1000 and could cause infinite loop, i.e

size_t off = SIZE_MAX - 50;
size_t endpages = SIZE_MAX;
off += 100; // off is now 50

if (off < endpages)
   prinf("off is still smaller!");

To prevent this the while loop could be written as:

while (off + 0x1000 < off && off < h->endpages) {
  off += 0x1000; 




More information about the Libguestfs mailing list