From: Tom Hughes Date: Mon, 18 Jul 2005 14:02:11 +0000 (+0000) Subject: Take a copy of the environment given to execve before trying to mangle X-Git-Tag: svn/VALGRIND_3_0_0~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a85d532b0def414788fa22f0777ab25c1c75c03f;p=thirdparty%2Fvalgrind.git Take a copy of the environment given to execve before trying to mangle it as it might be in read only memory. Fixes bug #101881. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4162 --- diff --git a/coregrind/m_libcproc.c b/coregrind/m_libcproc.c index d910bc7828..0851003e48 100644 --- a/coregrind/m_libcproc.c +++ b/coregrind/m_libcproc.c @@ -239,7 +239,7 @@ Int VG_(poll)( struct vki_pollfd *ufds, UInt nfds, Int timeout) } /* clone the environment */ -static Char **env_clone ( Char **oldenv ) +Char **VG_(env_clone) ( Char **oldenv ) { Char **oldenvp; Char **newenvp; @@ -284,7 +284,7 @@ Int VG_(system) ( Char* cmd ) /* restore the DATA rlimit for the child */ VG_(setrlimit)(VKI_RLIMIT_DATA, &VG_(client_rlimit_data)); - envp = env_clone(VG_(client_envp)); + envp = VG_(env_clone)(VG_(client_envp)); VG_(env_remove_valgrind_env_stuff)( envp ); argv[0] = "/bin/sh"; diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index 43a8a5a3be..42beaed30e 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -2271,6 +2271,7 @@ void VG_(reap_threads)(ThreadId self) PRE(sys_execve) { Char* path; /* path to executable */ + Char** envp; ThreadState* tst; PRINT("sys_execve ( %p(%s), %p, %p )", ARG1, ARG1, ARG2, ARG3); @@ -2317,14 +2318,13 @@ PRE(sys_execve) VG_(nuke_all_threads_except)( tid, VgSrc_ExitSyscall ); VG_(reap_threads)(tid); - { // Remove the valgrind-specific stuff from the environment so the - // child doesn't get vg_preload_core.so, vg_preload_TOOL.so, etc. - // This is done unconditionally, since if we are tracing the child, - // stage1/2 will set up the appropriate client environment. - Char** envp = (Char**)ARG3; - if (envp != NULL) { - VG_(env_remove_valgrind_env_stuff)( envp ); - } + // Remove the valgrind-specific stuff from the environment so the + // child doesn't get vg_preload_core.so, vg_preload_TOOL.so, etc. + // This is done unconditionally, since if we are tracing the child, + // stage1/2 will set up the appropriate client environment. + envp = VG_(env_clone)( (Char**)ARG3 ); + if (envp != NULL) { + VG_(env_remove_valgrind_env_stuff)( envp ); } if (VG_(clo_trace_children)) { diff --git a/coregrind/pub_core_libcproc.h b/coregrind/pub_core_libcproc.h index 69afe32565..451539914f 100644 --- a/coregrind/pub_core_libcproc.h +++ b/coregrind/pub_core_libcproc.h @@ -70,6 +70,7 @@ extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname, const Char *val ); extern void VG_(env_unsetenv) ( Char **env, const Char *varname ); extern void VG_(env_remove_valgrind_env_stuff) ( Char** env ); +extern Char **VG_(env_clone) ( Char **env_clone ); // misc extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout);