clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name quotaon.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/usr.sbin/quotaon/obj -resource-dir /usr/local/lib/clang/13.0.0 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/quotaon/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/usr.sbin/quotaon/quotaon.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 | #include <sys/types.h> |
37 | #include <sys/mount.h> |
38 | #include <ufs/ufs/quota.h> |
39 | |
40 | #include <err.h> |
41 | #include <stdio.h> |
42 | #include <stdlib.h> |
43 | #include <string.h> |
44 | #include <fstab.h> |
45 | #include <unistd.h> |
46 | |
47 | char *qfname = QUOTAFILENAME; |
48 | char *qfextension[] = INITQFNAMES; |
49 | |
50 | int aflag; |
51 | int gflag; |
52 | int uflag; |
53 | int vflag; |
54 | |
55 | void usage(char *whoami); |
56 | int hasquota(struct fstab *fs, int type, char **qfnamep, int force); |
57 | int quotaonoff(struct fstab *fs, int offmode, int type, char *qfpathname); |
58 | int oneof(char *target, char *list[], int cnt); |
59 | int readonly(struct fstab *fs); |
60 | |
61 | |
62 | int |
63 | main(int argc, char *argv[]) |
64 | { |
65 | struct fstab *fs; |
66 | char *qfnp, *whoami; |
67 | long argnum, done = 0; |
68 | int i, offmode = 0, errs = 0; |
69 | int ch; |
70 | |
71 | whoami = strrchr(*argv, '/') + 1; |
72 | if (whoami == (char *)1) |
| 1 | Assuming 'whoami' is not equal to 1 | |
|
| |
73 | whoami = *argv; |
74 | if (strcmp(whoami, "quotaoff") == 0) |
| 3 | | Assuming the condition is false | |
|
| |
75 | offmode = 1; |
76 | else if (strcmp(whoami, "quotaon") != 0) { |
| |
77 | fprintf(stderr, "Name must be quotaon or quotaoff not %s\n", |
78 | whoami); |
79 | exit(1); |
80 | } |
81 | while ((ch = getopt(argc, argv, "avug")) != -1) { |
| 6 | | Assuming the condition is false | |
|
| 7 | | Loop condition is false. Execution continues on line 99 | |
|
82 | switch (ch) { |
83 | case 'a': |
84 | aflag = 1; |
85 | break; |
86 | case 'g': |
87 | gflag = 1; |
88 | break; |
89 | case 'u': |
90 | uflag = 1; |
91 | break; |
92 | case 'v': |
93 | vflag = 1; |
94 | break; |
95 | default: |
96 | usage(whoami); |
97 | } |
98 | } |
99 | argc -= optind; |
100 | argv += optind; |
101 | if (argc <= 0 && !aflag) |
| |
102 | usage(whoami); |
103 | if (!gflag && !uflag) { |
| 9 | | Assuming 'gflag' is not equal to 0 | |
|
104 | gflag = 1; |
105 | uflag = 1; |
106 | } |
107 | setfsent(); |
108 | while ((fs = getfsent()) != NULL) { |
| 10 | | Assuming the condition is true | |
|
| 11 | | Loop condition is true. Entering loop body | |
|
109 | if (strcmp(fs->fs_type, FSTAB_RW)) |
| 12 | | Assuming the condition is false | |
|
| |
110 | continue; |
111 | if (strcmp(fs->fs_vfstype, "ffs") && |
| 14 | | Assuming the condition is false | |
|
112 | strcmp(fs->fs_vfstype, "ufs") && |
113 | strcmp(fs->fs_vfstype, "mfs")) |
114 | continue; |
115 | if (aflag) { |
| |
| |
116 | if (gflag && hasquota(fs, GRPQUOTA, &qfnp, 0)) |
117 | errs += quotaonoff(fs, offmode, GRPQUOTA, qfnp); |
118 | if (uflag && hasquota(fs, USRQUOTA, &qfnp, 0)) |
119 | errs += quotaonoff(fs, offmode, USRQUOTA, qfnp); |
120 | continue; |
121 | } |
122 | if ((argnum = oneof(fs->fs_file, argv, argc)) >= 0 || |
| 17 | | Assuming the condition is true | |
|
123 | (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) { |
124 | done |= 1 << argnum; |
125 | if (gflag) { |
| 18 | | Assuming 'gflag' is not equal to 0 | |
|
| |
126 | hasquota(fs, GRPQUOTA, &qfnp, 1); |
| |
127 | errs += quotaonoff(fs, offmode, GRPQUOTA, qfnp); |
128 | } |
129 | if (uflag) { |
130 | hasquota(fs, USRQUOTA, &qfnp, 1); |
131 | errs += quotaonoff(fs, offmode, USRQUOTA, qfnp); |
132 | } |
133 | } |
134 | } |
135 | endfsent(); |
136 | for (i = 0; i < argc; i++) |
137 | if ((done & (1 << i)) == 0) |
138 | fprintf(stderr, "%s not found in fstab\n", |
139 | argv[i]); |
140 | exit(errs); |
141 | } |
142 | |
143 | void |
144 | usage(char *whoami) |
145 | { |
146 | |
147 | fprintf(stderr, "usage: %s [-aguv] filesystem ...\n", whoami); |
148 | exit(1); |
149 | } |
150 | |
151 | int |
152 | quotaonoff(struct fstab *fs, int offmode, int type, char *qfpathname) |
153 | { |
154 | if (strcmp(fs->fs_file, "/") && readonly(fs)) |
155 | return (1); |
156 | if (offmode) { |
157 | if (quotactl(fs->fs_file, QCMD(Q_QUOTAOFF, type), 0, 0) < 0) { |
158 | fprintf(stderr, "quotaoff: "); |
159 | perror(fs->fs_file); |
160 | return (1); |
161 | } |
162 | if (vflag) |
163 | printf("%s: %s quotas turned off\n", fs->fs_file, |
164 | qfextension[type]); |
165 | return (0); |
166 | } |
167 | if (quotactl(fs->fs_file, QCMD(Q_QUOTAON, type), 0, qfpathname) < 0) { |
168 | warn("%s: %s quotas using %s", fs->fs_file, |
169 | qfextension[type], qfpathname); |
170 | return (1); |
171 | } |
172 | if (vflag) |
173 | printf("%s: %s quotas turned on\n", fs->fs_file, |
174 | qfextension[type]); |
175 | return (0); |
176 | } |
177 | |
178 | |
179 | |
180 | |
181 | int |
182 | oneof(char *target, char *list[], int cnt) |
183 | { |
184 | int i; |
185 | |
186 | for (i = 0; i < cnt; i++) |
187 | if (strcmp(target, list[i]) == 0) |
188 | return (i); |
189 | return (-1); |
190 | } |
191 | |
192 | |
193 | |
194 | |
195 | int |
196 | hasquota(struct fstab *fs, int type, char **qfnamep, int force) |
197 | { |
198 | char *opt; |
199 | char *cp; |
| 21 | | 'cp' declared without an initial value | |
|
200 | static char initname, usrname[100], grpname[100]; |
201 | static char buf[BUFSIZ]; |
202 | |
203 | if (!initname) { |
| |
204 | snprintf(usrname, sizeof usrname, "%s%s", |
205 | qfextension[USRQUOTA], qfname); |
206 | snprintf(grpname, sizeof grpname, "%s%s", |
207 | qfextension[GRPQUOTA], qfname); |
208 | initname = 1; |
209 | } |
210 | strlcpy(buf, fs->fs_mntops, sizeof buf); |
211 | for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { |
| 23 | | Loop condition is false. Execution continues on line 219 | |
|
212 | if ((cp = strchr(opt, '=')) != NULL) |
213 | *cp++ = '\0'; |
214 | if (type == USRQUOTA && strcmp(opt, usrname) == 0) |
215 | break; |
216 | if (type == GRPQUOTA && strcmp(opt, grpname) == 0) |
217 | break; |
218 | } |
219 | if (!force && !opt) |
220 | return (0); |
221 | if (cp) { |
| 24 | | Branch condition evaluates to a garbage value |
|
222 | *qfnamep = cp; |
223 | return (1); |
224 | } |
225 | (void) snprintf(buf, sizeof buf, "%s/%s.%s", fs->fs_file, |
226 | qfname, qfextension[type]); |
227 | *qfnamep = buf; |
228 | return (1); |
229 | } |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | int |
236 | readonly(struct fstab *fs) |
237 | { |
238 | struct statfs fsbuf; |
239 | |
240 | if (statfs(fs->fs_file, &fsbuf) < 0 || |
241 | strcmp(fsbuf.f_mntonname, fs->fs_file) || |
242 | strcmp(fsbuf.f_mntfromname, fs->fs_spec)) { |
243 | if (strcmp(fs->fs_file, "mfs") || |
244 | memcmp(fsbuf.f_mntfromname, "mfs:", sizeof("mfs:")-1)) |
245 | ; |
246 | else { |
247 | printf("%s: not mounted\n", fs->fs_file); |
248 | return (1); |
249 | } |
250 | } |
251 | if (fsbuf.f_flags & MNT_RDONLY) { |
252 | printf("%s: mounted read-only\n", fs->fs_file); |
253 | return (1); |
254 | } |
255 | return (0); |
256 | } |