mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: jason <jason@insomnia247.nl>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Bug in src/stdio/fread.c
Date: Sat, 10 Jul 2021 12:50:50 -0400	[thread overview]
Message-ID: <20210710165050.GU13220@brightrain.aerifal.cx> (raw)
In-Reply-To: <20210710131026.AE6BD22201B9@gateway02.insomnia247.nl>

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;
> 	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 = MIN(f->rend - f->rpos, l);
> 		memcpy(dest, f->rpos, k);
> 		f->rpos += k;
> 		dest += k;
> 		l -= k;
> 	}
> 	
> 	/* Read the remainder directly */
> 	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 16:51 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 [this message]
2021-07-10 17:13   ` David Edelsohn
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=20210710165050.GU13220@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).