Files
ftmemsim-valgrind/none/tests/allexec.c
Philippe Waroquiers c523185b76 fix 286270 VG_(env_remove_valgrind_env_stuff)
rev 12001 has introduced a regression in VG_(env_remove_valgrind_env_stuff):
to avoid modifying a possibly read-only env string, the string is duplicated,
and the copy is modified. However, mash_env_column modifies the string
"in-place". The modified string was not put back in the env (and could not,
because the src string is only partially copied).

This means that the valgrind preload strings were not cleaned up and
when a 32 bit executable execs a 64 bits (or vice versa: 64 bit execs 32 bits),
LD_PRELOAD contains both the 32 bits and 64 bits versions of Valgrind
vgpreload.... => ld.so then gives an error msg, as it can't preload either
the 32 or the 64 bits version.


The patch fixes this by duplicating the whole env string, and passing
to mash_colon_env a pointer to the correct offset in the whole env string.
The duplicated string is replacing the original entry in envp.

This patch adds two regression tests : none/tests/allexec32 and 
none/tests/allexec64. On a bi-arch valgrind, these will be 32bits and 64 bits
executables, exec-ing each other. On a single arch, one will be a symlink
to the other (to avoid different .exp files, and still test exec).



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12287
2011-12-11 16:29:43 +00:00

51 lines
1.6 KiB
C

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
extern char **environ;
#define S(...) (fprintf(stdout, __VA_ARGS__),fflush(stdout))
#define FORKEXECWAIT(exec_call) do { \
int status;\
pid_t child = fork(); \
if (child == 0) {exec_call; perror ("exec failed");} \
else if (child == -1) perror ("cannot fork\n"); \
else if (child != wait (&status)) perror ("error waiting child"); \
else S("child exited\n"); \
} while (0)
void test_allexec (char *exec)
{
FORKEXECWAIT (execlp(exec, exec, NULL));
FORKEXECWAIT (execlp(exec, exec, "constant_arg1", "constant_arg2", NULL));
FORKEXECWAIT (execve(exec, NULL, environ));
}
/* If a single argument "exec" is given, will execute itself
(in bi-arch, a 32 bit and 64 bit variant) via various exec system calls.
Note that this test can only be run after the prerequisite have been
prepared by allexec_prepare_prereq, which will a.o. make links
for the allexec32 and allexec64 executables. On single arch build,
these links points to the same executable to ensure this test works
everywhere the same.
No arguments or more arguments means just print its args. */
int main(int argc, char **argv, char **envp)
{
if ( (argc == 2) && (strcmp (argv[1], "exec") == 0)) {
S("%s will exec ./allexec32\n", argv[0]);
test_allexec ("./allexec32");
S("%s will exec ./allexec64\n", argv[0]);
test_allexec ("./allexec64");
} else {
int i;
S("program exec-ed:");
for (i = 0; i < argc; i++) S(" %s", argv[i]);
S("\n");
}
return 0;
}