diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2023-08-28 22:14:41 +0900 |
---|---|---|
committer | Takashi Yano <takashi.yano@nifty.ne.jp> | 2023-08-29 00:17:30 +0900 |
commit | 44f73c5a620689d6821c4bd0444051be57f8251a (patch) | |
tree | f4fd09528dfe641d98603d7ac03277eca7158ebf /winsup/cygwin/spawn.cc | |
parent | 50ff7901a5dbb2c57548d1bc125bbfbd17d37889 (diff) | |
download | newlib-44f73c5a620689d6821c4bd0444051be57f8251a.zip newlib-44f73c5a620689d6821c4bd0444051be57f8251a.tar.gz newlib-44f73c5a620689d6821c4bd0444051be57f8251a.tar.bz2 |
Cygwin: Fix segfalt when too many command line args are specified.
Previously, the number of command line args was not checked for
cygwin process. Due to this, segmentation fault was caused if too
many command line args are specified.
https://cygwin.com/pipermail/cygwin/2023-August/254333.html
Since char *argv[argc + 1] is placed on the stack in dll_crt0_1(),
STATUS_STACK_OVERFLOW occurs if the stack does not have enough
space.
With this patch, char *argv[] is placed in heap instead of stack
and ARG_MAX is increased from 32000 to 2097152 which is default
value of Linux. The argument length is also compared with ARG_MAX
and spawnve() returns E2BIG if it is too long.
Reported-by: Ed Morton
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r-- | winsup/cygwin/spawn.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index c16fe26..c4f1167 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -351,8 +351,9 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, We need to quote any argument that has whitespace or embedded "'s. */ int ac; + size_t arg_len = 0; for (ac = 0; argv[ac]; ac++) - /* nothing */; + arg_len += strlen (argv[ac]) + 1; int err; const char *ext; @@ -521,6 +522,12 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, __leave; } set (chtype, real_path.iscygexec ()); + if (iscygwin () && arg_len > (size_t) sysconf (_SC_ARG_MAX)) + { + set_errno (E2BIG); + res = -1; + __leave; + } __stdin = in__stdin; __stdout = in__stdout; record_children (); |