This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/78433] [7 Regression] glibc posix/execvpe.c gets miscompiled with -O3
- From: "vogt at linux dot vnet.ibm.com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 21 Nov 2016 10:11:04 +0000
- Subject: [Bug middle-end/78433] [7 Regression] glibc posix/execvpe.c gets miscompiled with -O3
- Auto-submitted: auto-generated
- References: <bug-78433-4@http.gcc.gnu.org/bugzilla/>
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.