summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2011-10-17 18:25:04 +0000
committerChristopher Faylor <me@cgf.cx>2011-10-17 18:25:04 +0000
commitce68abe0b4b2a71f6c224306f741c44d0138825a (patch)
treed9772967b0f42035f3705d9f5d8d794edffc385f
parente4257c736696e2f902bd06c96529fbfd98d13bbd (diff)
downloadcygnal-ce68abe0b4b2a71f6c224306f741c44d0138825a.tar.gz
cygnal-ce68abe0b4b2a71f6c224306f741c44d0138825a.tar.bz2
cygnal-ce68abe0b4b2a71f6c224306f741c44d0138825a.zip
* dcrt0.cc (dll_crt0_1): Copy argv before passing to main().
-rw-r--r--winsup/cygwin/ChangeLog4
-rw-r--r--winsup/cygwin/dcrt0.cc13
2 files changed, 16 insertions, 1 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index d250182dc..786c74258 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,9 @@
2011-10-17 Christopher Faylor <me.cygwin2011@cgf.cx>
+ * dcrt0.cc (dll_crt0_1): Copy argv before passing to main().
+
+2011-10-17 Christopher Faylor <me.cygwin2011@cgf.cx>
+
* sigproc.cc (proc_terminate): Avoid setting ppid to 1 if we're execing.
2011-10-15 Christopher Faylor <me.cygwin2011@cgf.cx>
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\