• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <pthread.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <sys/prctl.h>
7 #include <sys/types.h>
8 #include <unistd.h>
9 #include <assert.h>
10 
11 static pthread_t children[3];
12 
bad_things(int offset)13 void bad_things(int offset)
14 {
15   char* m = malloc(sizeof(char)*offset);
16   m[offset] = 0;
17   free(m);
18 }
19 
child_fn_2(void * arg)20 void* child_fn_2 ( void* arg )
21 {
22   const char* threadname = "012345678901234";
23 
24   pthread_setname_np(pthread_self(), threadname);
25 
26   bad_things(4);
27 
28   return NULL;
29 }
30 
child_fn_1(void * arg)31 void* child_fn_1 ( void* arg )
32 {
33   const char* threadname = "try1";
34   int r;
35 
36   pthread_setname_np(pthread_self(), threadname);
37 
38   bad_things(3);
39 
40   r = pthread_create(&children[2], NULL, child_fn_2, NULL);
41   assert(!r);
42 
43   r = pthread_join(children[2], NULL);
44   assert(!r);
45 
46   return NULL;
47 }
48 
child_fn_0(void * arg)49 void* child_fn_0 ( void* arg )
50 {
51   int r;
52 
53   bad_things(2);
54 
55   r = pthread_create(&children[1], NULL, child_fn_1, NULL);
56   assert(!r);
57 
58   r = pthread_join(children[1], NULL);
59   assert(!r);
60 
61   return NULL;
62 }
63 
main(int argc,const char ** argv)64 int main(int argc, const char** argv)
65 {
66   int r;
67 
68   bad_things(1);
69 
70   r = pthread_create(&children[0], NULL, child_fn_0, NULL);
71   assert(!r);
72 
73   r = pthread_join(children[0], NULL);
74   assert(!r);
75 
76   bad_things(5);
77 
78   return 0;
79 }
80 
81