diff options
author | Christopher Faylor <me@cgf.cx> | 2011-10-17 22:25:04 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2011-10-17 22:25:04 +0400 |
commit | ce68abe0b4b2a71f6c224306f741c44d0138825a (patch) | |
tree | d9772967b0f42035f3705d9f5d8d794edffc385f /winsup/cygwin/dcrt0.cc | |
parent | e4257c736696e2f902bd06c96529fbfd98d13bbd (diff) |
* dcrt0.cc (dll_crt0_1): Copy argv before passing to main().
Diffstat (limited to 'winsup/cygwin/dcrt0.cc')
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index f0980913f..dd3ff021c 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -894,7 +894,18 @@ dll_crt0_1 (void *) _setlocale_r (_REENT, LC_CTYPE, "C"); if (user_data->main) - cygwin_exit (user_data->main (__argc, __argv, *user_data->envptr)); + { + /* Create a copy of Cygwin's version of __argv so that, if the user makes + a change to an element of argv[] it does not affect Cygwin's argv. + Changing the the contents of what argv[n] points to will still + affect Cygwin. This is similar (but not exactly like) Linux. */ + char *newargv[__argc + 1]; + char **nav = newargv; + char **oav = __argv; + while ((*nav++ = *oav++) != NULL) + continue; + cygwin_exit (user_data->main (__argc, newargv, *user_data->envptr)); + } __asm__ (" \n\ .global __cygwin_exit_return \n\ __cygwin_exit_return: \n\ |