clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name dlltest.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/nss-scan-build/nspr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests -fcoverage-compilation-dir=/var/lib/jenkins/workspace/nss-scan-build/nspr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests -resource-dir /usr/lib/llvm-18/lib/clang/18 -U NDEBUG -D DEBUG_jenkins -D PACKAGE_NAME="" -D PACKAGE_TARNAME="" -D PACKAGE_VERSION="" -D PACKAGE_STRING="" -D PACKAGE_BUGREPORT="" -D PACKAGE_URL="" -D DEBUG=1 -D HAVE_VISIBILITY_HIDDEN_ATTRIBUTE=1 -D HAVE_VISIBILITY_PRAGMA=1 -D XP_UNIX=1 -D _GNU_SOURCE=1 -D HAVE_FCNTL_FILE_LOCKING=1 -D HAVE_POINTER_LOCALTIME_R=1 -D LINUX=1 -D HAVE_DLADDR=1 -D HAVE_GETTID=1 -D HAVE_LCHOWN=1 -D HAVE_SETPRIORITY=1 -D HAVE_STRERROR=1 -D HAVE_SYSCALL=1 -D HAVE_SECURE_GETENV=1 -D _REENTRANT=1 -D FORCE_PR_LOG -D _PR_PTHREADS -U HAVE_CVAR_BUILT_ON_SEM -I /var/lib/jenkins/workspace/nss-scan-build/nss/../dist/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/include -I ../../../pr/include -I ../../../pr/include/private -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fvisibility=hidden -fgnuc-version=4.2.1 -fno-inline -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-05-18-082241-28900-1 -x c ../../../pr/tests/dlltest.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | #include "prinit.h" |
27 | #include "prlink.h" |
28 | #include "prmem.h" |
29 | #include "prerror.h" |
30 | |
31 | #include "plstr.h" |
32 | |
33 | #include <stdio.h> |
34 | #include <stdlib.h> |
35 | |
36 | typedef PRIntn (PR_CALLBACK *GetFcnType)(void); |
37 | typedef void (PR_CALLBACK *SetFcnType)(PRIntn); |
38 | |
39 | PRIntn failed_already=0; |
40 | PRIntn debug_mode; |
41 | |
42 | int main(int argc, char** argv) |
43 | { |
44 | PRLibrary *lib, *lib2; |
45 | GetFcnType getFcn; |
46 | SetFcnType setFcn; |
47 | PRIntn value; |
48 | PRStatus status; |
49 | char *libName; |
50 | |
51 | if (argc >= 2 && PL_strcmp(argv[1], "-d") == 0) { |
| |
52 | debug_mode = 1; |
53 | } |
54 | |
55 | PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
56 | PR_STDIO_INIT(); |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | libName = PR_GetLibraryName("dll", "my"); |
64 | if (debug_mode) { |
| 2 | | Assuming 'debug_mode' is 0 | |
|
| |
65 | printf("Loading library %s\n", libName); |
66 | } |
67 | lib = PR_LoadLibrary(libName); |
68 | PR_FreeLibraryName(libName); |
69 | if (lib == NULL) { |
| 4 | | Assuming 'lib' is not equal to NULL | |
|
| |
70 | PRInt32 textLength = PR_GetErrorTextLength(); |
71 | char *text = (char*)PR_MALLOC(textLength + 1); |
72 | text[0] = '\0'; |
73 | (void)PR_GetErrorText(text); |
74 | fprintf( |
75 | stderr, "PR_LoadLibrary failed (%d, %d, %s)\n", |
76 | PR_GetError(), PR_GetOSError(), text); |
77 | if (!debug_mode) { |
78 | failed_already=1; |
79 | } |
80 | } |
81 | getFcn = (GetFcnType) PR_FindSymbol(lib, "My_GetValue"); |
82 | setFcn = (SetFcnType) PR_FindFunctionSymbol(lib, "My_SetValue"); |
83 | (*setFcn)(888); |
84 | value = (*getFcn)(); |
85 | if (value != 888) { |
| 6 | | Assuming 'value' is equal to 888 | |
|
| |
86 | fprintf(stderr, "Test 1 failed: set value to 888, but got %d\n", value); |
87 | if (!debug_mode) { |
88 | failed_already=1; |
89 | } |
90 | } |
91 | if (debug_mode) { |
| 8 | | Assuming 'debug_mode' is 0 | |
|
| |
92 | printf("Test 1 passed\n"); |
93 | } |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | getFcn = (GetFcnType) PR_FindSymbolAndLibrary("My_GetValue", &lib2); |
102 | if (NULL == getFcn || lib != lib2) { |
| 10 | | Assuming 'getFcn' is equal to NULL | |
|
103 | fprintf(stderr, "Test 2 failed: handles for the same library are not " |
104 | "equal: handle 1: %p, handle 2: %p\n", lib, lib2); |
105 | if (!debug_mode) { |
| 11 | | Assuming 'debug_mode' is not equal to 0 | |
|
| |
106 | failed_already=1; |
107 | } |
108 | } |
109 | setFcn = (SetFcnType) PR_FindSymbol(lib2, "My_SetValue"); |
110 | value = (*getFcn)(); |
| 13 | | Called function pointer is null (null dereference) |
|
111 | if (value != 888) { |
112 | fprintf(stderr, "Test 2 failed: value should be 888, but got %d\n", |
113 | value); |
114 | if (!debug_mode) { |
115 | failed_already=1; |
116 | } |
117 | } |
118 | (*setFcn)(777); |
119 | value = (*getFcn)(); |
120 | if (value != 777) { |
121 | fprintf(stderr, "Test 2 failed: set value to 777, but got %d\n", value); |
122 | if (!debug_mode) { |
123 | failed_already=1; |
124 | } |
125 | goto exit_now; |
126 | } |
127 | if (debug_mode) { |
128 | printf("Test 2 passed\n"); |
129 | } |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | status = PR_UnloadLibrary(lib); |
137 | if (PR_FAILURE == status) { |
138 | fprintf(stderr, "Test 3 failed: cannot unload library: (%d, %d)\n", |
139 | PR_GetError(), PR_GetOSError()); |
140 | if (!debug_mode) { |
141 | failed_already=1; |
142 | } |
143 | goto exit_now; |
144 | } |
145 | getFcn = (GetFcnType) PR_FindFunctionSymbol(lib2, "My_GetValue"); |
146 | setFcn = (SetFcnType) PR_FindSymbol(lib2, "My_SetValue"); |
147 | (*setFcn)(666); |
148 | value = (*getFcn)(); |
149 | if (value != 666) { |
150 | fprintf(stderr, "Test 3 failed: set value to 666, but got %d\n", value); |
151 | if (!debug_mode) { |
152 | failed_already=1; |
153 | } |
154 | goto exit_now; |
155 | } |
156 | if (debug_mode) { |
157 | printf("Test 3 passed\n"); |
158 | } |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | status = PR_UnloadLibrary(lib2); |
165 | if (PR_FAILURE == status) { |
166 | fprintf(stderr, "Test 4 failed: cannot unload library: (%d, %d)\n", |
167 | PR_GetError(), PR_GetOSError()); |
168 | if (!debug_mode) { |
169 | failed_already=1; |
170 | } |
171 | goto exit_now; |
172 | } |
173 | getFcn = (GetFcnType) PR_FindFunctionSymbolAndLibrary("My_GetValue", &lib2); |
174 | if (NULL != getFcn) { |
175 | fprintf(stderr, "Test 4 failed: how can we find a symbol " |
176 | "in an already unloaded library?\n"); |
177 | if (!debug_mode) { |
178 | failed_already=1; |
179 | } |
180 | goto exit_now; |
181 | } |
182 | if (debug_mode) { |
183 | printf("Test 4 passed\n"); |
184 | } |
185 | |
186 | |
187 | |
188 | |
189 | { |
190 | PRStaticLinkTable slt[10]; |
191 | PRLibrary *lib; |
192 | |
193 | lib = PR_LoadStaticLibrary( "my.dll", slt ); |
194 | if ( lib == NULL ) |
195 | { |
196 | fprintf(stderr, "Test 5: LoadStatiLibrary() failed\n" ); |
197 | goto exit_now; |
198 | } |
199 | if (debug_mode) |
200 | { |
201 | printf("Test 5 passed\n"); |
202 | } |
203 | } |
204 | |
205 | goto exit_now; |
206 | exit_now: |
207 | PR_Cleanup(); |
208 | |
209 | if (failed_already) { |
210 | printf("FAILED\n"); |
211 | return 1; |
212 | } else { |
213 | printf("PASSED\n"); |
214 | return 0; |
215 | } |
216 | } |