]> git.ipfire.org Git - thirdparty/glibc.git/commit
Fix writes past the allocated array bounds in execvpe (BZ#20847)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 21 Nov 2016 13:06:15 +0000 (11:06 -0200)
committerMike Frysinger <vapier@gentoo.org>
Thu, 8 Dec 2016 05:55:28 +0000 (00:55 -0500)
commit901db98f36690e4743feefd985c6ba2d7fd19813
tree350615c2dd60f1453c0eb17f8224a3ffd2d46de9
parentcaafe2b2612be88046d7bad4da42dbc2b07fbcd7
Fix writes past the allocated array bounds in execvpe (BZ#20847)

This patch fixes an invalid write out or stack allocated buffer in
2 places at execvpe implementation:

  1. On 'maybe_script_execute' function where it allocates the new
     argument list and it does not account that a minimum of argc
     plus 3 elements (default shell path, script name, arguments,
     and ending null pointer) should be considered.  The straightforward
     fix is just to take account of the correct list size on argument
     copy.

  2. On '__execvpe' where the executable file name lenght may not
     account for ending '\0' and thus subsequent path creation may
     write past array bounds because it requires to add the terminating
     null.  The fix is to change how to calculate the executable name
     size to add the final '\0' and adjust the rest of the code
     accordingly.

As described in GCC bug report 78433 [1], these issues were masked off by
GCC because it allocated several bytes more than necessary so that many
off-by-one bugs went unnoticed.

Checked on x86_64 with a latest GCC (7.0.0 20161121) with -O3 on CFLAGS.

[BZ #20847]
* posix/execvpe.c (maybe_script_execute): Remove write past allocated
array bounds.
(__execvpe): Likewise.

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

(cherry picked from commit d174436712e3cabce70d6cd771f177b6fe0e097b)
posix/execvpe.c