Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACJ51z2V+UCu5ZwKhJfty_HAwTVvEipYyQHHN181a+wg03er7Q@mail.gmail.com>
Date: Wed, 14 Feb 2018 14:48:14 -0500
From: Andrew Bell <andrew.bell.ia@...il.com>
To: musl@...ts.openwall.com
Subject: Re: fwrite() - possible division by zero

On Wed, Feb 14, 2018 at 2:39 PM, Markus Wichmann <nullplan@....net> wrote:

> On Wed, Feb 14, 2018 at 04:24:16PM -0200, Geraldo Netto wrote:
> > Dear Friends,
> >
> > I was playing with musl and I think I may have found an issue on
> fwrite():
> >
> > This is the original code:
> >
> > size_t fwrite(const void *restrict src, size_t size, size_t nmemb,
> > FILE *restrict f)
> > {
> >     size_t k, l = size*nmemb;
> >     if (!size) nmemb = 0;
> >     FLOCK(f);
> >     k = __fwritex(src, l, f);
> >     FUNLOCK(f);
> >     return k==l ? nmemb : k/size;
> > }
> >
>
> If size is zero, then l is zero. So __fwritex will be called with l as
> zero. Which means, if you read that code, that it will have to return
> zero.


Why not early return if size == 0 and avoid the call to __fwritex
altogether?

-- 
Andrew Bell
andrew.bell.ia@...il.com

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.