public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/68065] New: Size calculations for VLAs can overflow
@ 2015-10-23  8:36 ch3root at openwall dot com
  2015-10-23  9:22 ` [Bug c/68065] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: ch3root at openwall dot com @ 2015-10-23  8:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 68065
           Summary: Size calculations for VLAs can overflow
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ch3root at openwall dot com
  Target Milestone: ---

The following program crashes while writing to a buffer:

#include <stdint.h>
#include <stdio.h>

int main(void)
{
  size_t size = SIZE_MAX / sizeof(int) + 2;
  int buf[size];

  printf("%zu\n", sizeof(buf));
  for (size_t i = 0; i < size; i++)
    buf[i] = 1;

  return 0;
}

(Compile without optimization or make sure the loop is not optimized away.)

It would be better to detect an overflow in the size calculation and crash
right away, before any harm is done.

While at it, size of VLAs could probably be limited to PRTDIFF_MAX to be in
line with ordinary arrays.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-10-28 23:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-23  8:36 [Bug c/68065] New: Size calculations for VLAs can overflow 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
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

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).