]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Take a copy of the environment given to execve before trying to mangle
authorTom Hughes <tom@compton.nu>
Mon, 18 Jul 2005 14:02:11 +0000 (14:02 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 18 Jul 2005 14:02:11 +0000 (14:02 +0000)
it as it might be in read only memory. Fixes bug #101881.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4162

coregrind/m_libcproc.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/pub_core_libcproc.h

index d910bc78285612ac7a38e2bdf884649cbbc3f117..0851003e488b14bebad443b93853044d786599eb 100644 (file)
@@ -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";
index 43a8a5a3beb390e39be959ad36f745c5ba9d6651..42beaed30e8da59b0c489a151e3d61ab5c6dbb49 100644 (file)
@@ -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)) {
index 69afe3256586d3e2f742d5bb3cdf6e7bf283d264..451539914f943932a5fe9a5f8e5ef2983e523c38 100644 (file)
@@ -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);