[Bug middle-end/78433] [7 Regression] glibc posix/execvpe.c gets miscompiled with -O3

vogt at linux dot vnet.ibm.com gcc-bugzilla@gcc.gnu.org
Mon Nov 21 10:19:00 GMT 2016


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

--- Comment #8 from Dominik Vogt <vogt at linux dot vnet.ibm.com> ---
This code from maybe_script_execute() writes past the allocated array bounds:

  /* Construct an argument list for the shell. */
  char *new_argv[argc + 1];
                 ^^^^^^^^
  new_argv[0] = (char *) _PATH_BSHELL;
  new_argv[1] = (char *) file;
  if (argc > 1)
    memcpy (new_argv + 2, argv + 1, argc * sizeof(char *));
                    ^^^^^          ^^^^^^
  else
    new_argv[2] = NULL;
            ^^^

Before the patch, Gcc often allocated several bytes more than necessary so that
many off-by-one bugs went unnoticed.


More information about the Gcc-bugs mailing list