clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name popen.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/libexec/ftpd/obj -resource-dir /usr/local/llvm16/lib/clang/16 -I /usr/src/libexec/ftpd -I /usr/src/libexec/ftpd/../../bin/ls -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/libexec/ftpd/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/libexec/ftpd/popen.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 | |
34 | |
35 | |
36 | |
37 | #include <sys/types.h> |
38 | #include <sys/wait.h> |
39 | |
40 | #include <errno.h> |
41 | #include <glob.h> |
42 | #include <limits.h> |
43 | #include <signal.h> |
44 | #include <stdio.h> |
45 | #include <stdlib.h> |
46 | #include <string.h> |
47 | #include <syslog.h> |
48 | #include <unistd.h> |
49 | |
50 | #include <netinet/in.h> |
51 | |
52 | #include "monitor.h" |
53 | #include "extern.h" |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | FILE * |
62 | ftpd_ls(const char *path, pid_t *pidptr) |
63 | { |
64 | FILE *iop; |
65 | int argc = 0, pdes[2]; |
66 | pid_t pid; |
67 | char **pop, *argv[_POSIX_ARG_MAX]; |
68 | |
69 | if (pipe(pdes) == -1) |
| 1 | Assuming the condition is false | |
|
| |
70 | return (NULL); |
71 | |
72 | |
73 | argv[argc++] = "/bin/ls"; |
74 | argv[argc++] = "-lgA"; |
75 | argv[argc++] = "--"; |
76 | |
77 | |
78 | if (path != NULL) { |
| 3 | | Assuming 'path' is not equal to NULL | |
|
| |
79 | glob_t gl; |
80 | |
81 | memset(&gl, 0, sizeof(gl)); |
82 | if (glob(path, |
| 5 | | Assuming the condition is false | |
|
| |
83 | GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE|GLOB_LIMIT, |
84 | NULL, &gl)) { |
85 | fatal ("Glob error."); |
86 | } else if (gl.gl_pathc > 0) { |
| 7 | | Assuming field 'gl_pathc' is > 0 | |
|
| |
87 | for (pop = gl.gl_pathv; *pop && argc < _POSIX_ARG_MAX-1; |
| 9 | | Assuming the condition is true | |
|
| 10 | | Loop condition is true. Entering loop body | |
|
| 13 | | Assuming the condition is true | |
|
| 14 | | Loop condition is true. Entering loop body | |
|
| 18 | | Assuming the condition is false | |
|
88 | pop++) { |
89 | argv[argc++] = strdup(*pop); |
| |
90 | if (argv[argc - 1] == NULL) |
| 11 | | Assuming the condition is true | |
|
| |
| 16 | | Assuming the condition is false | |
|
| |
91 | fatal ("Out of memory."); |
92 | } |
93 | } |
94 | globfree(&gl); |
95 | } |
96 | argv[argc] = NULL; |
97 | |
98 | iop = NULL; |
99 | |
100 | switch (pid = fork()) { |
| 19 | | Control jumps to 'case -1:' at line 101 | |
|
101 | case -1: |
102 | (void)close(pdes[0]); |
103 | (void)close(pdes[1]); |
104 | goto pfree; |
| 20 | | Control jumps to line 127 | |
|
105 | |
106 | case 0: |
107 | if (pdes[1] != STDOUT_FILENO) { |
108 | dup2(pdes[1], STDOUT_FILENO); |
109 | (void)close(pdes[1]); |
110 | } |
111 | dup2(STDOUT_FILENO, STDERR_FILENO); |
112 | (void)close(pdes[0]); |
113 | closelog(); |
114 | |
115 | extern int ls_main(int, char **); |
116 | |
117 | |
118 | optreset = optind = 1; |
119 | exit(ls_main(argc, argv)); |
120 | } |
121 | |
122 | iop = fdopen(pdes[0], "r"); |
123 | (void)close(pdes[1]); |
124 | *pidptr = pid; |
125 | |
126 | pfree: |
127 | for (argc = 3; argv[argc] != NULL; argc++) |
| 21 | | Loop condition is false. Execution continues on line 130 | |
|
128 | free(argv[argc]); |
129 | |
130 | return (iop); |
| |
131 | } |
132 | |
133 | int |
134 | ftpd_pclose(FILE *iop, pid_t pid) |
135 | { |
136 | int status; |
137 | pid_t rv; |
138 | sigset_t sigset, osigset; |
139 | |
140 | (void)fclose(iop); |
141 | sigemptyset(&sigset); |
142 | sigaddset(&sigset, SIGINT); |
143 | sigaddset(&sigset, SIGQUIT); |
144 | sigaddset(&sigset, SIGHUP); |
145 | sigprocmask(SIG_BLOCK, &sigset, &osigset); |
146 | while ((rv = waitpid(pid, &status, 0)) == -1 && errno == EINTR) |
147 | continue; |
148 | sigprocmask(SIG_SETMASK, &osigset, NULL); |
149 | if (rv == -1) |
150 | return (-1); |
151 | if (WIFEXITED(status)) |
152 | return (WEXITSTATUS(status)); |
153 | return (1); |
154 | } |