|
Message-ID: <CAGWvny=BSuvfmVeDAyMoNR1RCx5eVau3vR3fuNeURmEWNzUwmw@mail.gmail.com> Date: Sat, 10 Jul 2021 13:13:55 -0400 From: David Edelsohn <dje.gcc@...il.com> To: musl@...ts.openwall.com Cc: jason <jason@...omnia247.nl> Subject: Re: Bug in src/stdio/fread.c On Sat, Jul 10, 2021 at 12:51 PM Rich Felker <dalias@...c.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
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.