vfs: check userland buffers before reading them.
[haiku.git] / src / tests / system / runtime_loader / test_suite / dlopen_lookup_next1
blob7317873c3a1e00ad4b705043b34d055b4ee94d59
1 #!/bin/sh
3 # program
5 # dlopen():
6 # libe.so
7 # liba.so
8 # <- libb.so
9 # <- libd.so
11 # Expected: dlsym(RTLD_NEXT) finds symbol in order libe.so, liba.so, libb.so,
12 # libd.so
15 . ./test_setup
18 # create libd.so
19 cat > libd.c << EOI
20 int a() { return 1; }
21 EOI
23 # build
24 compile_lib -o libd.so libd.c
27 # create libb.so
28 cat > libb.c << EOI
29 #define __USE_GNU
30 #include <dlfcn.h>
31 int
32 a()
34 int (*nextA)();
35 *(void**)&nextA = dlsym(RTLD_NEXT, "a");
36 return (nextA != 0 ? nextA() : 0) + 2;
38 EOI
40 # build
41 compile_lib_dl -o libb.so libb.c ./libd.so
44 # create liba.so
45 cat > liba.c << EOI
46 #include <dlfcn.h>
47 int
48 a()
50 int (*nextA)();
51 *(void**)&nextA = dlsym(RTLD_NEXT, "a");
52 return (nextA != 0 ? nextA() : 0) + 4;
54 EOI
56 # build
57 compile_lib_dl -o liba.so liba.c ./libb.so
60 # create libe.so
61 cat > libe.c << EOI
62 #include <dlfcn.h>
63 int
64 a()
66 int (*nextA)();
67 *(void**)&nextA = dlsym(RTLD_NEXT, "a");
68 return (nextA != 0 ? nextA() : 0) + 8;
70 EOI
72 # build
73 compile_lib_dl -o libe.so libe.c
76 # create program
77 cat > program.c << EOI
78 #include <dlfcn.h>
79 #include <stdio.h>
80 #include <stdlib.h>
82 int
83 a()
85 int (*nextA)();
86 *(void**)&nextA = dlsym(RTLD_NEXT, "a");
87 return (nextA != 0 ? nextA() : 0) + 16;
90 int
91 main()
93 void* liba;
94 void* libe;
95 void* self;
97 libe = dlopen("./libe.so", RTLD_NOW | RTLD_GLOBAL);
98 if (libe == NULL) {
99 fprintf(stderr, "Error opening libe.so: %s\n", dlerror());
100 exit(117);
103 liba = dlopen("./liba.so", RTLD_NOW | RTLD_GLOBAL);
104 if (liba == NULL) {
105 fprintf(stderr, "Error opening liba.so: %s\n", dlerror());
106 exit(117);
109 return a();
113 # build
114 compile_program_dl -o program program.c
116 # run
117 test_run_ok ./program 31