clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name rstatd.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 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -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/rpc.rstatd/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/libexec/rpc.rstatd/../../usr.bin/vmstat -D NOKVM -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/libexec/rpc.rstatd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -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/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/libexec/rpc.rstatd/rstatd.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 | #include <sys/types.h> |
32 | #include <sys/socket.h> |
33 | #include <stdio.h> |
34 | #include <stdlib.h> |
35 | #include <string.h> |
36 | #include <unistd.h> |
37 | #include <limits.h> |
38 | #include <signal.h> |
39 | #include <pwd.h> |
40 | #include <syslog.h> |
41 | #include <errno.h> |
42 | #include <rpc/rpc.h> |
43 | #include <rpcsvc/rstat.h> |
44 | |
45 | extern void rstat_service(struct svc_req *, SVCXPRT *); |
46 | |
47 | void my_svc_run(void); |
48 | |
49 | int from_inetd = 1; |
50 | int closedown = 20; |
51 | |
52 | volatile sig_atomic_t gotsig; |
53 | |
54 | |
55 | static void |
56 | getsig(int signo) |
57 | { |
58 | gotsig = 1; |
59 | } |
60 | |
61 | |
62 | int |
63 | main(int argc, char *argv[]) |
64 | { |
65 | int sock = 0, proto = 0; |
66 | socklen_t fromlen; |
67 | struct passwd *pw; |
68 | struct sockaddr_storage from; |
69 | SVCXPRT *transp; |
70 | |
71 | openlog("rpc.rstatd", LOG_NDELAY|LOG_CONS|LOG_PID, LOG_DAEMON); |
72 | |
73 | if ((pw = getpwnam("_rstatd")) == NULL) { |
| 1 | Assuming the condition is false | |
|
| |
74 | syslog(LOG_ERR, "no such user _rstatd"); |
75 | exit(1); |
76 | } |
77 | if (chroot("/var/empty") == -1) { |
| 3 | | Assuming the condition is false | |
|
| |
78 | syslog(LOG_ERR, "cannot chdir to /var/empty."); |
79 | exit(1); |
80 | } |
81 | chdir("/"); |
82 | |
83 | setgroups(1, &pw->pw_gid); |
84 | setegid(pw->pw_gid); |
85 | setgid(pw->pw_gid); |
86 | seteuid(pw->pw_uid); |
87 | setuid(pw->pw_uid); |
88 | |
89 | if (argc == 2) |
| 5 | | Assuming 'argc' is not equal to 2 | |
|
| |
90 | closedown = strtonum(argv[1], 1, INT_MAX, NULL); |
91 | if (closedown == 0) |
| |
92 | closedown = 20; |
93 | |
94 | |
95 | |
96 | |
97 | fromlen = sizeof(from); |
98 | if (getsockname(0, (struct sockaddr *)&from, &fromlen) == -1) { |
| 8 | | Assuming the condition is false | |
|
| |
99 | from_inetd = 0; |
100 | sock = RPC_ANYSOCK; |
101 | proto = IPPROTO_UDP; |
102 | } |
103 | |
104 | if (!from_inetd) { |
| |
105 | daemon(0, 0); |
106 | |
107 | (void)pmap_unset(RSTATPROG, RSTATVERS_TIME); |
108 | (void)pmap_unset(RSTATPROG, RSTATVERS_SWTCH); |
109 | (void)pmap_unset(RSTATPROG, RSTATVERS_ORIG); |
110 | |
111 | (void) signal(SIGINT, getsig); |
112 | (void) signal(SIGTERM, getsig); |
113 | (void) signal(SIGHUP, getsig); |
114 | } |
115 | |
116 | transp = svcudp_create(sock); |
117 | if (transp == NULL) { |
| 11 | | Assuming 'transp' is not equal to NULL | |
|
| |
118 | syslog(LOG_ERR, "cannot create udp service."); |
119 | exit(1); |
120 | } |
121 | if (!svc_register(transp, RSTATPROG, RSTATVERS_TIME, rstat_service, proto)) { |
| 13 | | Assuming the condition is false | |
|
| |
122 | syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, udp)."); |
123 | exit(1); |
124 | } |
125 | if (!svc_register(transp, RSTATPROG, RSTATVERS_SWTCH, rstat_service, proto)) { |
| 15 | | Assuming the condition is false | |
|
| |
126 | syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, udp)."); |
127 | exit(1); |
128 | } |
129 | if (!svc_register(transp, RSTATPROG, RSTATVERS_ORIG, rstat_service, proto)) { |
| 17 | | Assuming the condition is false | |
|
| |
130 | syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, udp)."); |
131 | exit(1); |
132 | } |
133 | |
134 | my_svc_run(); |
| |
135 | syslog(LOG_ERR, "svc_run returned"); |
136 | exit(1); |
137 | } |
138 | |
139 | void |
140 | my_svc_run(void) |
141 | { |
142 | extern volatile sig_atomic_t wantupdatestat; |
143 | extern void updatestat(void); |
144 | struct pollfd *pfd = NULL, *newp; |
| 20 | | 'pfd' initialized to a null pointer value | |
|
145 | int nready, saved_max_pollfd = 0; |
146 | |
147 | for (;;) { |
| 21 | | Loop condition is true. Entering loop body | |
|
148 | if (wantupdatestat) { |
| 22 | | Assuming 'wantupdatestat' is 0 | |
|
| |
149 | wantupdatestat = 0; |
150 | updatestat(); |
151 | } |
152 | if (gotsig) { |
| |
| |
153 | (void) pmap_unset(RSTATPROG, RSTATVERS_TIME); |
154 | (void) pmap_unset(RSTATPROG, RSTATVERS_SWTCH); |
155 | (void) pmap_unset(RSTATPROG, RSTATVERS_ORIG); |
156 | exit(0); |
157 | } |
158 | if (svc_max_pollfd > saved_max_pollfd) { |
| 26 | | Assuming 'svc_max_pollfd' is <= 'saved_max_pollfd' | |
|
| |
159 | newp = reallocarray(pfd, svc_max_pollfd, sizeof(*pfd)); |
160 | if (newp == NULL) { |
161 | free(pfd); |
162 | perror("svc_run: - realloc failed"); |
163 | return; |
164 | } |
165 | pfd = newp; |
166 | saved_max_pollfd = svc_max_pollfd; |
167 | } |
168 | memcpy(pfd, svc_pollfd, svc_max_pollfd * sizeof(*pfd)); |
| 28 | | Null pointer passed as 1st argument to memory copy function |
|
169 | |
170 | nready = poll(pfd, svc_max_pollfd, INFTIM); |
171 | switch (nready) { |
172 | case -1: |
173 | if (errno == EINTR) |
174 | continue; |
175 | perror("svc_run: - poll failed"); |
176 | free(pfd); |
177 | return; |
178 | case 0: |
179 | continue; |
180 | default: |
181 | svc_getreq_poll(pfd, nready); |
182 | } |
183 | } |
184 | } |