Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/dlltest.c
Warning:line 110, column 13
Called function pointer is null (null dereference)

Annotated Source Code

Press '?' to see keyboard shortcuts

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/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6/***********************************************************************
7**
8** Name: dlltest.c
9**
10** Description: test dll functionality.
11**
12** Modification History:
13** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
14** The debug mode will print all of the printfs associated with this test.
15** The regress mode will be the default mode. Since the regress tool limits
16** the output to a one line status:PASS or FAIL,all of the printf statements
17** have been handled with an if (debug_mode) statement.
18** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
19** recognize the return code from tha main program.
20** 12-June-97 Revert to return code 0 and 1.
21***********************************************************************/
22
23/***********************************************************************
24** Includes
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
36typedef PRIntn (PR_CALLBACK *GetFcnType)(void);
37typedef void (PR_CALLBACK *SetFcnType)(PRIntn);
38
39PRIntn failed_already=0;
40PRIntn debug_mode;
41
42int main(int argc, char** argv)
43{
44 PRLibrary *lib, *lib2; /* two handles to the same library */
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) {
1
Assuming 'argc' is < 2
52 debug_mode = 1;
53 }
54
55 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
56 PR_STDIO_INIT();
57
58 /*
59 * Test 1: load the library, look up the symbols, call the functions,
60 * and check the results.
61 */
62
63 libName = PR_GetLibraryName("dll", "my");
64 if (debug_mode) {
2
Assuming 'debug_mode' is 0
3
Taking false branch
65 printf("Loading library %s\n", libName);
66 }
67 lib = PR_LoadLibrary(libName);
68 PR_FreeLibraryName(libName);
69 if (lib == NULL((void*)0)) {
4
Assuming 'lib' is not equal to NULL
5
Taking false branch
70 PRInt32 textLength = PR_GetErrorTextLength();
71 char *text = (char*)PR_MALLOC(textLength + 1)(PR_Malloc((textLength + 1)));
72 text[0] = '\0';
73 (void)PR_GetErrorText(text);
74 fprintf(
75 stderrstderr, "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
7
Taking false branch
86 fprintf(stderrstderr, "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
9
Taking false branch
92 printf("Test 1 passed\n");
93 }
94
95 /*
96 * Test 2: get a second handle to the same library (this should increment
97 * the reference count), look up the symbols, call the functions, and
98 * check the results.
99 */
100
101 getFcn = (GetFcnType) PR_FindSymbolAndLibrary("My_GetValue", &lib2);
102 if (NULL((void*)0) == getFcn || lib != lib2) {
10
Assuming 'getFcn' is equal to NULL
103 fprintf(stderrstderr, "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
12
Taking false branch
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(stderrstderr, "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(stderrstderr, "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 * Test 3: unload the library. The library should still be accessible
133 * via the second handle. do the same things as above.
134 */
135
136 status = PR_UnloadLibrary(lib);
137 if (PR_FAILURE == status) {
138 fprintf(stderrstderr, "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(stderrstderr, "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 * Test 4: unload the library, testing the reference count mechanism.
162 */
163
164 status = PR_UnloadLibrary(lib2);
165 if (PR_FAILURE == status) {
166 fprintf(stderrstderr, "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((void*)0) != getFcn) {
175 fprintf(stderrstderr, "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 ** Test 5: LoadStaticLibrary()
188 */
189 {
190 PRStaticLinkTable slt[10];
191 PRLibrary *lib;
192
193 lib = PR_LoadStaticLibrary( "my.dll", slt );
194 if ( lib == NULL((void*)0) )
195 {
196 fprintf(stderrstderr, "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;
206exit_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}