public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bugdal at aerifal dot cx" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/27214] The C frontend introduces undefined pointer overflow
Date: Sun, 06 May 2012 04:23:00 -0000	[thread overview]
Message-ID: <bug-27214-4-UxQnXvSCtN@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-27214-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27214

Rich Felker <bugdal at aerifal dot cx> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugdal at aerifal dot cx

--- Comment #11 from Rich Felker <bugdal at aerifal dot cx> 2012-05-06 04:11:03 UTC ---
I would lean towards marking this one invalid. Under normal circumstances (and
I would argue, under ALL conditions, on a high-quality implementation), objects
cannot be larger than SIZE_MAX/2. This is because ptrdiff_t has been chosen to
be the signed type corresponding to size_t, and if objects larger than
SIZE_MAX/2 were allowed, valid pointer subtractions would overflow the signed
ptrdiff_t and result in undefined behavior.

There are three ways of addressing this issue; either:
(1) you say "subtracting pointers is unsafe unless the application makes an
effort to ensure that no huge objects exist" even though that's hard to do in
any portable way; OR
(2) you disallow objects sufficiently large that ptrdiff_t would overflow; OR
(3) you make ptrdiff_t a larger type (e.g. 64-bit on 32-bit systems). But this
is not an option since you're always dealing with an already-defined ABI.

If you take option (1), large objects (>SIZE_MAX/2) are already extremely
dangerous and so the additional wrapping issue in GCC's internal representation
is a really small matter in comparison. If you take option (2), offsets can
always be interpreted as the signed type.


       reply	other threads:[~2012-05-06  4:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-27214-4@http.gcc.gnu.org/bugzilla/>
2012-05-06  4:23 ` bugdal at aerifal dot cx [this message]
2012-05-07  9:21 ` rguenth at gcc dot gnu.org
2021-03-25 14:11 ` rguenth at gcc dot gnu.org
2006-04-19 11:44 [Bug c/27214] New: " rguenth at gcc dot gnu dot org
2006-04-19 15:06 ` [Bug c/27214] " pinskia at gcc dot gnu dot org
2006-04-19 15:13 ` rguenth at gcc dot gnu dot org
2006-04-19 15:22 ` pinskia at gcc dot gnu dot org
2006-04-19 15:31 ` rguenth at gcc dot gnu dot org
2006-04-19 15:34 ` pinskia at gcc dot gnu dot org
2006-04-19 16:32 ` rakdver at gcc dot gnu dot org
2006-04-19 17:15 ` joseph at codesourcery dot com
2006-05-05  9:23 ` pinskia at gcc dot gnu dot org
2007-12-11  0:46 ` pinskia at gcc dot gnu dot org
2008-01-03 16:25 ` rguenth at gcc dot gnu dot org

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=bug-27214-4-UxQnXvSCtN@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).