public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "joseph at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/68065] Size calculations for VLAs can overflow
Date: Wed, 28 Oct 2015 13:15:00 -0000	[thread overview]
Message-ID: <bug-68065-4-WeNJZO5iSG@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-68065-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68065

--- Comment #11 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Wed, 28 Oct 2015, ch3root at openwall dot com wrote:

> --- Comment #10 from Alexander Cherepanov <ch3root at openwall dot com> ---
> On 2015-10-27 20:09, joseph at codesourcery dot com wrote:
> > I think it's undefined at the point where a type exceeds the limit on the
> > size of an object
> 
> This would probably be the most reasonable approach but it's not clear 
> if the text of the standard supports it. E.g., the list of UB (C11, 
> J.2p1) includes this one:
> 
>    - The size expression in an array declaration is not a constant 
> expression and evaluates at program execution time to a nonpositive 
> value (6.7.6.2).
> 
> but I don't see anything like what you described. Perhaps I'm missing 
> something?

The standard has a list of minimum implementation limits, but it is not 
exhaustive as to all areas in which there may be limits.  I think it is 
reasonable to consider "bytes in an object" to cover such limits for any 
object type, whether or not an object of that type is constructed.

It is well-known that strictly conforming programs do not exist when you 
interpret the standard strictly.

The existence of rsize_t in Annex K hints at the likelihood of problems 
with objects larger than SIZE_MAX >> 1 bytes.

> This is also very nice approach. (Although it seems to differ from the 
> approach to non-VLA arrays in 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68107#c1 .) But, again, I 

It's universally the case that size-related things that are constraint 
violations (compile-time errors) for non-VLAs are runtime undefined 
behavior for VLAs.  This applies to size overflow just as to e.g. 
non-positive array sizes.

There are also lots of details around evaluation of VLA sizes that the C 
standard is silent on (the C standard doesn't really have a notion of type 
names being evaluated at all, only expressions, but VLAs in type names 
only make sense when type names get evaluated at an appropriate point in 
execution) that I had to fill out when sorting out constant expressions 
and VLAs issues for GCC 4.5.


  parent reply	other threads:[~2015-10-28 13:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23  8:36 [Bug c/68065] New: " ch3root at openwall dot com
2015-10-23  9:22 ` [Bug c/68065] " pinskia at gcc dot gnu.org
2015-10-23 16:22 ` joseph at codesourcery dot com
2015-10-27  0:06 ` ch3root at openwall dot com
2015-10-27  0:15 ` joseph at codesourcery dot com
2015-10-27 14:25 ` ch3root at openwall dot com
2015-10-27 17:09 ` joseph at codesourcery dot com
2015-10-27 18:29 ` danielmicay at gmail dot com
2015-10-28 11:28 ` ch3root at openwall dot com
2015-10-28 13:15 ` joseph at codesourcery dot com [this message]
2015-10-28 16:35 ` ebotcazou at gcc dot gnu.org
2015-10-28 23:30 ` ch3root at openwall dot com
2015-10-28 23:38 ` joseph at codesourcery dot com
2015-10-28 23:43 ` ch3root at openwall dot com

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-68065-4-WeNJZO5iSG@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).