mailing list of musl libc
 help / color / mirror / code / Atom feed
From: David Edelsohn <dje.gcc@gmail.com>
To: musl@lists.openwall.com
Cc: jason <jason@insomnia247.nl>
Subject: Re: [musl] Bug in src/stdio/fread.c
Date: Sat, 10 Jul 2021 13:13:55 -0400	[thread overview]
Message-ID: <CAGWvny=BSuvfmVeDAyMoNR1RCx5eVau3vR3fuNeURmEWNzUwmw@mail.gmail.com> (raw)
In-Reply-To: <20210710165050.GU13220@brightrain.aerifal.cx>

On Sat, Jul 10, 2021 at 12:51 PM Rich Felker <dalias@libc.org> wrote:
>
> On Sat, Jul 10, 2021 at 03:10:26PM +0200, jason wrote:
> > If you look at the code:
> >
> > size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
> > {
> >       unsigned char *dest = destv;

k declared but not initialized.

> >       size_t len = size*nmemb, l = len, k;
> >       if (!size) nmemb = 0;
> >
> >       FLOCK(f);
> >
> >       f->mode |= f->mode-1;
> >
> >       if (f->rpos != f->rend) {
> >               /* First exhaust the buffer. */

k set to value.

> >               k = MIN(f->rend - f->rpos, l);
> >               memcpy(dest, f->rpos, k);
> >               f->rpos += k;
> >               dest += k;
> >               l -= k;
> >       }
> >
> >       /* Read the remainder directly */

USE of k.  If f->rpos == f->rend, k was never set before use for the
first iteration of the loop.

> >       for (; l; l-=k, dest+=k) {
> >               k = __toread(f) ? 0 : f->read(f, dest, l);
> >               if (!k) {
> >                       FUNLOCK(f);
> >                       return (len-l)/size;
> >               }
> >       }
> >
> >       FUNLOCK(f);
> >       return nmemb;
> > }
> >
> > Consider what happens when f->rpos == f->rend: k is used uninitialized.
>
> At which line?
>
> Rich

  reply	other threads:[~2021-07-10 17:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-10 13:10 jason
2021-07-10 16:50 ` Rich Felker
2021-07-10 17:13   ` David Edelsohn [this message]
2021-07-10 17:17     ` David Edelsohn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGWvny=BSuvfmVeDAyMoNR1RCx5eVau3vR3fuNeURmEWNzUwmw@mail.gmail.com' \
    --to=dje.gcc@gmail.com \
    --cc=jason@insomnia247.nl \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).