]> sourceware.org Git - newlib-cygwin.git/commit
Cygwin: execve: drop argument size limit
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 29 Aug 2023 09:55:10 +0000 (11:55 +0200)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 29 Aug 2023 12:17:04 +0000 (14:17 +0200)
commitca2a4ec243627b19f0ac2c7262703f81712f3be4
tree31a15406dc5dbb0a038632beaad61a4d2cd7ee31
parent42eb6e5ddf49d81a17fffa1caaf61a668aab4692
Cygwin: execve: drop argument size limit

Before commit 44f73c5a6206 ("Cygwin: Fix segfalt when too many command
line args are specified.") we had no actual argument size limit, except
for the fact that the child process created another copy of the argv
array on the stack, which could result in a stack overflow and a
subsequent SEGV.  Commit 44f73c5a6206 changed that by allocating the
additional argv array via malloc, and it introduced a new SC_ARG_MAX
limit along the lines of the typical Linux limit.

However, this new limit is artificial. Cygwin allocates all argument
and environment data on the cygheap.  We only run out of ARG_MAX space
if we're out of memory resources.

Change argument size handling accordingly:
- Drop the args size check from  child_info_spawn::worker.
- Return -1 from sysconf (SC_ARG_MAX), i. e., the argument size limit
  is undefined.
- Change argv handling in class av, so that a failing cmalloc is not
  fatal.  This allows the parent process to return E2BIG if it's out
  of cygheap resources.
- In the child, add a check around the new malloc call, so that it
  doesn't result in a SEGV if the child process gets unexpectedly into
  an ENOMEM situation at this point. In this (unlikely) case, proceed
  with the original __argv array instead.  Add comment to explain why.

Fixes: 44f73c5a6206 ("Cygwin: Fix segfalt when too many command line args are specified.")
Tested-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/dcrt0.cc
winsup/cygwin/kernel32.cc
winsup/cygwin/local_includes/winf.h
winsup/cygwin/local_includes/winsup.h
winsup/cygwin/spawn.cc
winsup/cygwin/sysconf.cc
This page took 0.029934 seconds and 5 git commands to generate.