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

            Bug ID: 71422
           Summary: Total size of static objects is not limited
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ch3root at openwall dot com
  Target Milestone: ---

Shouldn't gcc loudly fail when it cannot lay static objects out without
wrapping around the end of the address space?
Otherwise the resulting binary can, for example, crash. Or silently give wrong
answer like in the example below.

Source code:

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

char a[SIZE_MAX / 2];
char b[SIZE_MAX / 2];
char c[SIZE_MAX / 2];

int main(int argc, char **argv)
{
  (void)argv;

  a[argc] = 123;
  printf("%d\n", b[argc]);

  printf("&a = %p\n", (void *)&a);
  printf("&b = %p\n", (void *)&b);
  printf("&c = %p\n", (void *)&c);
}
----------------------------------------------------------------------

Results:

----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 -m32 test.c && ./a.out
123
&a = 0x8049740
&b = 0x8049740
&c = 0x88049740
----------------------------------------------------------------------

gcc version: gcc (GCC) 7.0.0 20160604 (experimental)

Reply via email to