clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name unoapploader.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -std=gnu89 -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c /home/maarten/src/libreoffice/core/odk/source/unoapploader/unx/unoapploader.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | #include <stdlib.h> |
21 | #include <unistd.h> |
22 | #include <stdio.h> |
23 | #include <string.h> |
24 | #include <sys/stat.h> |
25 | |
26 | #ifdef LINUX |
27 | #define __USE_GNU |
28 | #endif |
29 | #include <dlfcn.h> |
30 | |
31 | #include <cppuhelper/findsofficepath.h> |
32 | #include <rtl/string.h> |
33 | #include <sal/types.h> |
34 | |
35 | static char* getPath(void); |
36 | static char* createCommandName( char* argv0 ); |
37 | |
38 | static const int SEPARATOR = '/'; |
39 | static const char* PATHSEPARATOR = ":"; |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | int main( int argc, char *argv[] ) |
65 | { |
66 | char* path; |
67 | char* cmdname; |
68 | |
69 | (void) argc; |
70 | |
71 | |
72 | path = getPath(); |
73 | |
74 | if ( path != NULL ) |
| |
75 | { |
76 | #if defined(MACOSX) |
77 | static const char* ENVVARNAME = "DYLD_LIBRARY_PATH"; |
78 | #elif defined(AIX) |
79 | static const char* ENVVARNAME = "LIBPATH"; |
80 | #else |
81 | static const char* ENVVARNAME = "LD_LIBRARY_PATH"; |
82 | #endif |
83 | char* libpath; |
84 | char* value; |
85 | char* envstr; |
86 | int size; |
87 | |
88 | size_t pathlen = strlen(path); |
89 | struct stat stats; |
90 | int ret; |
91 | |
92 | static char const unoinfoSuffix[] = "/unoinfo"; |
93 | char * unoinfo = malloc( |
94 | pathlen + RTL_CONSTASCII_LENGTH(unoinfoSuffix) + 1); |
95 | |
96 | if (unoinfo == NULL) { |
| 2 | | Assuming 'unoinfo' is not equal to NULL | |
|
| |
97 | free(path); |
98 | fprintf(stderr, "Error: out of memory!\n"); |
99 | exit(EXIT_FAILURE); |
100 | } |
101 | strcpy(unoinfo, path); |
102 | strcpy( |
103 | unoinfo + pathlen, |
104 | unoinfoSuffix + (pathlen == 0 || path[pathlen - 1] != '/' ? 0 : 1)); |
| 4 | | Assuming 'pathlen' is equal to 0 | |
|
105 | ret = lstat(unoinfo, &stats); |
106 | free(unoinfo); |
107 | |
108 | if (ret == 0) { |
| 5 | | Assuming 'ret' is not equal to 0 | |
|
| |
109 | char * cmd = malloc( |
110 | 2 * pathlen + RTL_CONSTASCII_LENGTH("/unoinfo c++") + 1); |
111 | |
112 | char const * p; |
113 | char * q; |
114 | FILE * f; |
115 | size_t n = 1000; |
116 | size_t old = 0; |
117 | if (cmd == NULL) { |
118 | fprintf(stderr, "Error: out of memory!\n"); |
119 | exit(EXIT_FAILURE); |
120 | } |
121 | p = path; |
122 | q = cmd; |
123 | while (*p != '\0') { |
124 | *q++ = '\\'; |
125 | *q++ = *p++; |
126 | } |
127 | if (p == path || p[-1] != '/') { |
128 | *q++ = '/'; |
129 | } |
130 | strcpy(q, "unoinfo c++"); |
131 | f = popen(cmd, "r"); |
132 | free(cmd); |
133 | if (f == NULL) |
134 | { |
135 | fprintf(stderr, "Error: calling unoinfo failed!\n"); |
136 | exit(EXIT_FAILURE); |
137 | } |
138 | libpath = NULL; |
139 | for (;;) { |
140 | size_t m; |
141 | libpath = realloc(libpath, n); |
142 | if (libpath == NULL) { |
143 | fprintf( |
144 | stderr, |
145 | "Error: out of memory reading unoinfo output!\n"); |
146 | exit(EXIT_FAILURE); |
147 | } |
148 | m = fread(libpath + old, 1, n - old - 1, f); |
149 | if (m != n - old - 1) { |
150 | if (ferror(f)) { |
151 | fprintf(stderr, "Error: cannot read unoinfo output!\n"); |
152 | exit(EXIT_FAILURE); |
153 | } |
154 | libpath[old + m] = '\0'; |
155 | break; |
156 | } |
157 | if (n >= SAL_MAX_SIZE / 2) { |
158 | fprintf( |
159 | stderr, |
160 | "Error: out of memory reading unoinfo output!\n"); |
161 | exit(EXIT_FAILURE); |
162 | } |
163 | old = n - 1; |
164 | n *= 2; |
165 | } |
166 | if (pclose(f) != 0) { |
167 | fprintf(stderr, "Error: executing unoinfo failed!\n"); |
168 | exit(EXIT_FAILURE); |
169 | } |
170 | free(path); |
171 | } |
172 | else |
173 | { |
174 | |
175 | libpath = path; |
176 | } |
177 | |
178 | value = getenv( ENVVARNAME ); |
179 | |
180 | |
181 | |
182 | #ifdef MACOSX |
183 | size = strlen( ENVVARNAME ) + strlen( "=/usr/lib:" ) + strlen( libpath ) + 1; |
184 | #else |
185 | size = strlen( ENVVARNAME ) + strlen( "=" ) + strlen( libpath ) + 1; |
186 | #endif |
187 | if ( value != NULL ) |
| 7 | | Assuming 'value' is equal to NULL | |
|
| |
188 | size += strlen( PATHSEPARATOR ) + strlen( value ); |
189 | envstr = (char*) malloc( size ); |
| |
190 | strcpy( envstr, ENVVARNAME ); |
191 | #ifdef MACOSX |
192 | strcat( envstr, "=/usr/lib:" ); |
193 | #else |
194 | strcat( envstr, "=" ); |
195 | #endif |
196 | strcat( envstr, libpath ); |
197 | free( libpath ); |
198 | if ( value != NULL ) |
| |
199 | { |
200 | strcat( envstr, PATHSEPARATOR ); |
201 | strcat( envstr, value ); |
202 | } |
203 | |
204 | putenv( envstr ); |
205 | } |
206 | else |
207 | { |
208 | fprintf( stderr, "Warning: no office installation found!\n" ); |
209 | fflush( stderr ); |
210 | } |
211 | |
212 | |
213 | cmdname = createCommandName( argv[0] ); |
| 11 | | Potential leak of memory pointed to by 'envstr' |
|
214 | argv[0] = cmdname; |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | execvp( cmdname, argv ); |
222 | fprintf( stderr, "Error: execvp failed!\n" ); |
223 | fflush( stderr ); |
224 | |
225 | return 0; |
226 | } |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | char* getPath(void) |
236 | { |
237 | char* path = cppuhelper_detail_findSofficePath(); |
238 | |
239 | if ( path == NULL ) |
240 | { |
241 | fprintf( stderr, "Warning: getting path from PATH environment " |
242 | "variable failed!\n" ); |
243 | fflush( stderr ); |
244 | } |
245 | |
246 | return path; |
247 | } |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | char* createCommandName( char* argv0 ) |
260 | { |
261 | const char* CMDPREFIX = "_"; |
262 | const char* prgname = NULL; |
263 | |
264 | char* cmdname = NULL; |
265 | char* sep = NULL; |
266 | #ifndef AIX |
267 | Dl_info dl_info; |
268 | #endif |
269 | |
270 | |
271 | prgname = argv0; |
272 | |
273 | #ifndef AIX |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | if ( argv0 != NULL && *argv0 != SEPARATOR && |
280 | dladdr( (void*) &createCommandName, &dl_info ) && |
281 | dl_info.dli_fname != NULL && *dl_info.dli_fname == SEPARATOR ) |
282 | { |
283 | prgname = dl_info.dli_fname; |
284 | } |
285 | #endif |
286 | |
287 | |
288 | if ( prgname != NULL ) |
289 | { |
290 | cmdname = (char*) malloc( strlen( prgname ) + strlen( CMDPREFIX ) + 1 ); |
291 | sep = strrchr( prgname, SEPARATOR ); |
292 | if ( sep != NULL ) |
293 | { |
294 | int pos = ++sep - prgname; |
295 | strncpy( cmdname, prgname, pos ); |
296 | cmdname[ pos ] = '\0'; |
297 | strcat( cmdname, CMDPREFIX ); |
298 | strcat( cmdname, sep ); |
299 | } |
300 | else |
301 | { |
302 | strcpy( cmdname, CMDPREFIX ); |
303 | strcat( cmdname, prgname ); |
304 | } |
305 | } |
306 | |
307 | return cmdname; |
308 | } |
309 | |
310 | |