]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/restest2.c
Fix bad pointer / leak in regex code
[thirdparty/glibc.git] / elf / restest2.c
1 #include <sys/types.h>
2 #include <dlfcn.h>
3 #include <error.h>
4 #include <mcheck.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7
8 pid_t pid, pid2;
9
10 pid_t getpid(void)
11 {
12 pid_t (*f)(void);
13 f = (pid_t (*)(void)) dlsym (RTLD_NEXT, "getpid");
14 if (f == NULL)
15 error (EXIT_FAILURE, 0, "dlsym (RTLD_NEXT, \"getpid\"): %s", dlerror ());
16 return (pid2 = f()) + 26;
17 }
18
19 int
20 main (void)
21 {
22 pid_t (*f)(void);
23
24 mtrace ();
25
26 f = (pid_t (*)(void)) dlsym (RTLD_DEFAULT, "getpid");
27 if (f == NULL)
28 error (EXIT_FAILURE, 0, "dlsym (RTLD_DEFAULT, \"getpid\"): %s", dlerror ());
29 pid = f();
30 if (pid != pid2 + 26)
31 error (EXIT_FAILURE, 0, "main getpid() not called");
32 return 0;
33 }