clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.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 -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sbin/restore/obj -resource-dir /usr/local/llvm16/lib/clang/16 -D RRESTORE -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/sbin/restore/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fno-jump-tables -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/scan/2024-01-11-140451-98009-1 -x c /usr/src/sbin/restore/main.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 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | #include <sys/stat.h> |
34 | #include <sys/time.h> |
35 | |
36 | #include <ufs/ffs/fs.h> |
37 | #include <ufs/ufs/dinode.h> |
38 | #include <protocols/dumprestore.h> |
39 | |
40 | #include <err.h> |
41 | #include <paths.h> |
42 | #include <signal.h> |
43 | #include <stdio.h> |
44 | #include <stdlib.h> |
45 | #include <string.h> |
46 | #include <unistd.h> |
47 | #include <limits.h> |
48 | |
49 | #include "restore.h" |
50 | #include "extern.h" |
51 | |
52 | int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0; |
53 | int hflag = 1, mflag = 1, Nflag = 0; |
54 | char command = '\0'; |
55 | long dumpnum = 1; |
56 | long volno = 0; |
57 | long ntrec; |
58 | char *dumpmap; |
59 | char *usedinomap; |
60 | ino_t maxino; |
61 | time_t dumptime; |
62 | time_t dumpdate; |
63 | FILE *terminal; |
64 | char *tmpdir; |
65 | |
66 | static void obsolete(int *, char **[]); |
67 | static void usage(void); |
68 | |
69 | int |
70 | main(int argc, char *argv[]) |
71 | { |
72 | int ch; |
73 | ino_t ino; |
74 | char *inputdev; |
75 | char *symtbl = "./restoresymtable"; |
76 | char *p, name[PATH_MAX]; |
77 | |
78 | |
79 | (void)umask(077); |
80 | |
81 | if (argc < 2) |
| |
82 | usage(); |
83 | |
84 | if ((inputdev = getenv("TAPE")) == NULL || *inputdev == '\0') |
| 2 | | Assuming the environment variable does not exist | |
|
85 | inputdev = _PATH_DEFTAPE; |
86 | if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') |
| 3 | | Assuming the environment variable exists | |
|
| 4 | | Assuming the condition is false | |
|
| |
87 | tmpdir = _PATH_TMP; |
88 | if ((tmpdir = strdup(tmpdir)) == NULL) |
| 6 | | Assuming the condition is false | |
|
| |
89 | err(1, NULL); |
90 | for (p = tmpdir + strlen(tmpdir) - 1; p >= tmpdir && *p == '/'; p--) |
| 8 | | Assuming 'p' is < 'tmpdir' | |
|
91 | continue; |
92 | obsolete(&argc, &argv); |
| |
| 18 | | Returned allocated memory via 2nd parameter | |
|
93 | while ((ch = getopt(argc, argv, "b:cdf:himNRrs:tvxy")) != -1) |
| 19 | | Assuming the condition is false | |
|
| 20 | | Loop condition is false. Execution continues on line 150 | |
|
94 | switch(ch) { |
95 | case 'b': |
96 | |
97 | bflag = 1; |
98 | ntrec = strtol(optarg, &p, 10); |
99 | if (*p) |
100 | errx(1, "illegal blocksize -- %s", optarg); |
101 | if (ntrec <= 0) |
102 | errx(1, "block size must be greater than 0"); |
103 | break; |
104 | case 'c': |
105 | cvtflag = 1; |
106 | break; |
107 | case 'd': |
108 | dflag = 1; |
109 | break; |
110 | case 'f': |
111 | inputdev = optarg; |
112 | break; |
113 | case 'h': |
114 | hflag = 0; |
115 | break; |
116 | case 'i': |
117 | case 'R': |
118 | case 'r': |
119 | case 't': |
120 | case 'x': |
121 | if (command != '\0') |
122 | errx(1, |
123 | "%c and %c options are mutually exclusive", |
124 | ch, command); |
125 | command = ch; |
126 | break; |
127 | case 'm': |
128 | mflag = 0; |
129 | break; |
130 | case 'N': |
131 | Nflag = 1; |
132 | break; |
133 | case 's': |
134 | |
135 | dumpnum = strtol(optarg, &p, 10); |
136 | if (*p) |
137 | errx(1, "illegal dump number -- %s", optarg); |
138 | if (dumpnum <= 0) |
139 | errx(1, "dump number must be greater than 0"); |
140 | break; |
141 | case 'v': |
142 | vflag = 1; |
143 | break; |
144 | case 'y': |
145 | yflag = 1; |
146 | break; |
147 | default: |
148 | usage(); |
149 | } |
150 | argc -= optind; |
151 | argv += optind; |
152 | |
153 | if (command == '\0') |
| 21 | | Assuming the condition is false | |
|
| |
154 | errx(1, "none of i, R, r, t or x options specified"); |
155 | |
156 | if (signal(SIGINT, onintr) == SIG_IGN) |
| 23 | | Assuming the condition is false | |
|
| |
157 | (void)signal(SIGINT, SIG_IGN); |
158 | if (signal(SIGTERM, onintr) == SIG_IGN) |
| 25 | | Assuming the condition is false | |
|
| |
159 | (void)signal(SIGTERM, SIG_IGN); |
160 | setvbuf(stderr, NULL, _IOLBF, 0); |
161 | |
162 | atexit(cleanup); |
163 | |
164 | setinput(inputdev); |
165 | |
166 | if (argc == 0) { |
| 27 | | Assuming 'argc' is not equal to 0 | |
|
| |
167 | argc = 1; |
168 | *--argv = "."; |
169 | } |
170 | |
171 | switch (command) { |
172 | |
173 | |
174 | |
175 | case 'i': |
176 | setup(); |
177 | extractdirs(1); |
178 | initsymtable(NULL); |
179 | runcmdshell(); |
180 | break; |
181 | |
182 | |
183 | |
184 | case 'r': |
185 | setup(); |
186 | if (dumptime > 0) { |
187 | |
188 | |
189 | |
190 | Vprintf(stdout, "Begin incremental restore\n"); |
191 | initsymtable(symtbl); |
192 | extractdirs(1); |
193 | removeoldleaves(); |
194 | Vprintf(stdout, "Calculate node updates.\n"); |
195 | treescan(".", ROOTINO, nodeupdates); |
196 | findunreflinks(); |
197 | removeoldnodes(); |
198 | } else { |
199 | |
200 | |
201 | |
202 | Vprintf(stdout, "Begin level 0 restore\n"); |
203 | initsymtable(NULL); |
204 | extractdirs(1); |
205 | Vprintf(stdout, "Calculate extraction list.\n"); |
206 | treescan(".", ROOTINO, nodeupdates); |
207 | } |
208 | createleaves(symtbl); |
209 | createlinks(); |
210 | setdirmodes(FORCE); |
211 | checkrestore(); |
212 | if (dflag) { |
213 | Vprintf(stdout, "Verify the directory structure\n"); |
214 | treescan(".", ROOTINO, verifyfile); |
215 | } |
216 | dumpsymtable(symtbl, (long)1); |
217 | break; |
218 | |
219 | |
220 | |
221 | case 'R': |
222 | initsymtable(symtbl); |
223 | skipmaps(); |
224 | skipdirs(); |
225 | createleaves(symtbl); |
226 | createlinks(); |
227 | setdirmodes(FORCE); |
228 | checkrestore(); |
229 | dumpsymtable(symtbl, (long)1); |
230 | break; |
231 | |
232 | |
233 | |
234 | case 't': |
235 | setup(); |
236 | extractdirs(0); |
237 | initsymtable(NULL); |
238 | while (argc--) { |
239 | canon(*argv++, name, sizeof name); |
240 | ino = dirlookup(name); |
241 | if (ino == 0) |
242 | continue; |
243 | treescan(name, ino, listfile); |
244 | } |
245 | break; |
246 | |
247 | |
248 | |
249 | case 'x': |
250 | setup(); |
251 | extractdirs(1); |
252 | initsymtable(NULL); |
253 | while (argc--) { |
254 | canon(*argv++, name, sizeof name); |
255 | ino = dirlookup(name); |
256 | if (ino == 0) |
257 | continue; |
258 | if (mflag) |
259 | pathcheck(name); |
260 | treescan(name, ino, addfile); |
261 | } |
262 | createfiles(); |
263 | createlinks(); |
264 | setdirmodes(0); |
265 | if (dflag) |
266 | checkrestore(); |
267 | break; |
268 | } |
269 | return (0); |
| 29 | | 'Default' branch taken. Execution continues on line 269 | |
|
| 30 | | Potential leak of memory pointed to by 'argv' |
|
270 | } |
271 | |
272 | static void |
273 | usage(void) |
274 | { |
275 | |
276 | (void)fprintf(stderr, "usage: %s [-chimRrtvxy] [-b blocksize] [-f file] [-s fileno] [file ...]\n", __progname); |
277 | exit(1); |
278 | } |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | static void |
286 | obsolete(int *argcp, char **argvp[]) |
287 | { |
288 | int argc, flags; |
289 | char *ap, **argv, *flagsp, **nargv, *p; |
290 | size_t len; |
291 | |
292 | |
293 | argv = *argvp; |
294 | argc = *argcp; |
295 | |
296 | |
297 | ap = argv[1]; |
298 | if (argc == 1 || *ap == '-') |
| 10 | | Assuming the condition is false | |
|
299 | return; |
300 | |
301 | |
302 | if ((*argvp = nargv = calloc(argc + 1, sizeof(char *))) == NULL || |
| |
| 12 | | Assuming the condition is false | |
|
| |
303 | (p = flagsp = malloc(strlen(ap) + 2)) == NULL) |
| 13 | | Assuming the condition is false | |
|
304 | err(1, NULL); |
305 | |
306 | *nargv++ = *argv; |
307 | argv += 2; |
308 | |
309 | for (flags = 0; *ap; ++ap) { |
| 15 | | Loop condition is false. Execution continues on line 338 | |
|
310 | switch (*ap) { |
311 | case 'b': |
312 | case 'f': |
313 | case 's': |
314 | if (*argv == NULL) { |
315 | warnx("option requires an argument -- %c", *ap); |
316 | usage(); |
317 | } |
318 | len = strlen(*argv) + 2 + 1; |
319 | if ((nargv[0] = malloc(len)) == NULL) |
320 | err(1, NULL); |
321 | nargv[0][0] = '-'; |
322 | nargv[0][1] = *ap; |
323 | (void)strlcpy(&nargv[0][2], *argv, len-2); |
324 | ++argv; |
325 | ++nargv; |
326 | break; |
327 | default: |
328 | if (!flags) { |
329 | *p++ = '-'; |
330 | flags = 1; |
331 | } |
332 | *p++ = *ap; |
333 | break; |
334 | } |
335 | } |
336 | |
337 | |
338 | if (flags) { |
| |
339 | *p = '\0'; |
340 | *nargv++ = flagsp; |
341 | } else { |
342 | free(flagsp); |
343 | } |
344 | |
345 | |
346 | while ((*nargv++ = *argv++)) |
| 17 | | Loop condition is false. Execution continues on line 350 | |
|
347 | continue; |
348 | |
349 | |
350 | *argcp = nargv - *argvp - 1; |
351 | } |