1 /* Reproduces bug 321960 (based on test from Daniel Stodden).
2 At least on Ubuntu 12 and 13, causes invalid write errors
3 in __yell or the memset call (due to some part of the main
4 stack being marked as not addressable in memcheck).
5 Bug seems extremely sensitive to initial conditions:
6 Depending on the size of the env, bug is triggered or not.
7 Also, a high nr of threads in thr[] is needed to get
27 memset(buf
, 0, sizeof(buf
));
30 /* Without argument, executes once.
31 Otherwise first arg indicates nr of times the process will exec
32 itself, each time increasing the size of the environment
33 by about 50 characters. */
34 int main(int argc
, char **argv
, char** envp
)
39 for (i
= 0; i
< sizeof(thr
) / sizeof(*thr
); i
++) {
40 err
= pthread_create(&thr
[i
], NULL
, nop
, NULL
);
47 for (i
= 0; i
< sizeof(thr
) / sizeof(*thr
); i
++)
48 pthread_join(thr
[i
], NULL
);
50 if ( argc
== 2 && atoi(argv
[1]) > 0) {
51 /* exec ourselves with some more env */
57 sprintf(more_env
, "N%d=ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", atoi(argv
[1]));
58 for (j
= 0; envp
[j
]; j
++)
60 new_env
= malloc((j
+2) * sizeof(char*));
61 assert (new_env
!= NULL
);
62 for (i
= 0; i
< j
; i
++)
64 new_env
[i
++] = more_env
;
67 sprintf (n
, "%d", atoi(argv
[1]) - 1);
68 // system ("env | wc");
69 execle(argv
[0], argv
[0], n
, NULL
, new_env
);