public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Ian Lance Taylor <iant@golang.org>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: libbacktrace patch RFC: check size passed to backtrace_get_view
Date: Fri, 18 Jan 2019 16:18:00 -0000	[thread overview]
Message-ID: <78f94cee-a15c-e783-b73e-f9215b5eba56@suse.de> (raw)
In-Reply-To: <CAKOQZ8xKWT4AcGVXG-=brvvgE_oXmwtzO8+uRm+ax-4SDtrSZg@mail.gmail.com>

On 18-01-19 16:40, Ian Lance Taylor wrote:
>  int
>  backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED,
> -		    int descriptor, off_t offset, size_t size,
> +		    int descriptor, off_t offset, uint64_t size,
>  		    backtrace_error_callback error_callback,
>  		    void *data, struct backtrace_view *view)
>  {
> @@ -60,6 +60,12 @@ backtrace_get_view (struct backtrace_sta
>    off_t pageoff;
>    void *map;
>  
> +  if ((uint64_t) (size_t) size != size)
> +    {
> +      error_callback (data, "file size too large", 0);
> +      return 0;
> +    }
> +

Agreed, this will fix the PR.

There's a cornercase I'm not sure is worth bothering about, but given
that this is an RFC: in the case of 32-bit systems with 32-bit
filesystem, there will be a range of numbers that fit in size_t, but are
too large for off_t (both 32-bit but size_t unsigned and off_t signed),
so in that case, the file size is too large, but we're not detecting
that here. Though I think that should be handled in the subsequent mmap
(or, in the case of read.c, in the subsequent read(), though I'm
guessing the earlier backtrace_alloc > 2GB will already fail).

Thanks,
- Tom

  reply	other threads:[~2019-01-18 16:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-18 15:40 Ian Lance Taylor
2019-01-18 16:18 ` Tom de Vries [this message]
2019-01-18 17:16   ` Ian Lance Taylor

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=78f94cee-a15c-e783-b73e-f9215b5eba56@suse.de \
    --to=tdevries@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iant@golang.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).