Bug Summary

File:src/usr.bin/getconf/getconf.c
Warning:line 532, column 9
Potential leak of memory pointed to by 'sval'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name getconf.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.bin/getconf/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.bin/getconf/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.bin/getconf/getconf.c
1/* $OpenBSD: getconf.c,v 1.21 2021/07/12 15:09:19 beck Exp $ */
2
3/*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by J.T. Conklin.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Winning Strategies, Inc.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36/*
37 * POSIX.2 getconf utility
38 *
39 * Written by:
40 * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
41 */
42
43#include <err.h>
44#include <errno(*__errno()).h>
45#include <limits.h>
46#include <stdio.h>
47#include <stdlib.h>
48#include <string.h>
49#include <unistd.h>
50
51static void __dead__attribute__((__noreturn__)) usage(void);
52static void list_var(int);
53static int compilation_spec_valid(const char *);
54
55struct conf_variable
56{
57 const char *name;
58 enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT } type;
59 long value;
60};
61
62
63#define constant_row(name) { #name, CONSTANT, name },
64#define sysconf_row(name) { #name, SYSCONF, _SC_##name },
65#define pathconf_row(name) { #name, PATHCONF, _PC_##name },
66#define confstr_row(name) { #name, CONFSTR, _CS_##name },
67#define posix_constant_row(name) { #name, CONSTANT, _POSIX_##name },
68#define posix_confstr_row(name) { #name, CONFSTR, _CS_POSIX_##name },
69#define compat_posix2_sysconf_row(name) { #name, SYSCONF, _SC_2_##name },
70#define compat_posix2_constant_row(name) { #name, CONSTANT, _POSIX2_##name },
71
72/* Some sysconf variables don't follow the pattern of the others */
73#define posix2_sysconf_row(name){ "_POSIX2_" "name", SYSCONF, _SC_2_name }, \
74 { "_POSIX2_" #name, SYSCONF, _SC_2_##name },
75#define posix2_pathconf_row(name){ "_POSIX2_" "name", PATHCONF, _PC_2_name }, \
76 { "_POSIX2_" #name, PATHCONF, _PC_2_##name },
77#define pthread_sysconf_row(name){ "_PTHREAD_" "name", SYSCONF, _SC_THREAD_name }, \
78 { "_PTHREAD_" #name, SYSCONF, _SC_THREAD_##name },
79#define xopen_sysconf_row(name){ "_XOPEN_" "name", SYSCONF, _SC_XOPEN_name }, \
80 { "_XOPEN_" #name, SYSCONF, _SC_XOPEN_##name },
81
82const struct conf_variable conf_table[] =
83{
84 /* Configuration strings */
85 confstr_row(PATH)
86 confstr_row(V7_ENV)
87 confstr_row(V6_ENV)
88
89 /* Symbolic Utility Limits */
90 sysconf_row(BC_BASE_MAX2147483647)
91 sysconf_row(BC_DIM_MAX65535)
92 sysconf_row(BC_SCALE_MAX2147483647)
93 sysconf_row(BC_STRING_MAX2147483647)
94 sysconf_row(COLL_WEIGHTS_MAX2)
95 sysconf_row(EXPR_NEST_MAX32)
96 sysconf_row(LINE_MAX2048)
97 sysconf_row(RE_DUP_MAX255)
98
99 /* POSIX.1 Configurable System Variables */
100 sysconf_row(AIO_LISTIO_MAX)
101 sysconf_row(AIO_MAX)
102 sysconf_row(AIO_PRIO_DELTA_MAX)
103 sysconf_row(ARG_MAX(512 * 1024))
104 sysconf_row(CHILD_MAX80)
105 sysconf_row(CLK_TCK)
106 sysconf_row(NGROUPS_MAX16)
107 sysconf_row(OPEN_MAX64)
108 sysconf_row(STREAM_MAX)
109 sysconf_row(TZNAME_MAX)
110 sysconf_row(PAGE_SIZE)
111 sysconf_row(PAGESIZE)
112
113 sysconf_row(SEM_NSEMS_MAX)
114 sysconf_row(SEM_VALUE_MAX(2147483647 *2U +1U))
115 sysconf_row(HOST_NAME_MAX255)
116 sysconf_row(LOGIN_NAME_MAX32)
117
118 sysconf_row(ATEXIT_MAX)
119 sysconf_row(DELAYTIMER_MAX)
120 sysconf_row(IOV_MAX1024)
121 sysconf_row(MQ_OPEN_MAX)
122 sysconf_row(MQ_PRIO_MAX)
123 sysconf_row(RTSIG_MAX)
124 sysconf_row(SIGQUEUE_MAX)
125 sysconf_row(SYMLOOP_MAX32)
126 sysconf_row(TIMER_MAX)
127 sysconf_row(TTY_NAME_MAX260)
128
129 posix2_sysconf_row(PBS){ "_POSIX2_" "PBS", SYSCONF, 35 },
130 posix2_sysconf_row(PBS_ACCOUNTING){ "_POSIX2_" "PBS_ACCOUNTING", SYSCONF, 36 },
131 posix2_sysconf_row(PBS_CHECKPOINT){ "_POSIX2_" "PBS_CHECKPOINT", SYSCONF, 37 },
132 posix2_sysconf_row(PBS_LOCATE){ "_POSIX2_" "PBS_LOCATE", SYSCONF, 38 },
133 posix2_sysconf_row(PBS_MESSAGE){ "_POSIX2_" "PBS_MESSAGE", SYSCONF, 39 },
134 posix2_sysconf_row(PBS_TRACK){ "_POSIX2_" "PBS_TRACK", SYSCONF, 40 },
135
136 pthread_sysconf_row(DESTRUCTOR_ITERATIONS){ "_PTHREAD_" "DESTRUCTOR_ITERATIONS", SYSCONF, 80 },
137 pthread_sysconf_row(KEYS_MAX){ "_PTHREAD_" "KEYS_MAX", SYSCONF, 81 },
138 pthread_sysconf_row(STACK_MIN){ "_PTHREAD_" "STACK_MIN", SYSCONF, 89 },
139 pthread_sysconf_row(THREADS_MAX){ "_PTHREAD_" "THREADS_MAX", SYSCONF, 90 },
140
141 xopen_sysconf_row(SHM){ "_XOPEN_" "SHM", SYSCONF, 30 },
142 xopen_sysconf_row(CRYPT){ "_XOPEN_" "CRYPT", SYSCONF, 117 },
143 xopen_sysconf_row(ENH_I18N){ "_XOPEN_" "ENH_I18N", SYSCONF, 118 },
144 xopen_sysconf_row(REALTIME){ "_XOPEN_" "REALTIME", SYSCONF, 120 },
145 xopen_sysconf_row(REALTIME_THREADS){ "_XOPEN_" "REALTIME_THREADS", SYSCONF, 121 },
146 xopen_sysconf_row(STREAMS){ "_XOPEN_" "STREAMS", SYSCONF, 122 },
147 xopen_sysconf_row(UNIX){ "_XOPEN_" "UNIX", SYSCONF, 123 },
148 xopen_sysconf_row(UUCP){ "_XOPEN_" "UUCP", SYSCONF, 124 },
149 xopen_sysconf_row(VERSION){ "_XOPEN_" "VERSION", SYSCONF, 125 },
150
151 pathconf_row(FILESIZEBITS)
152 pathconf_row(LINK_MAX32767)
153 pathconf_row(MAX_CANON255)
154 pathconf_row(MAX_INPUT255)
155 pathconf_row(NAME_MAX255)
156 pathconf_row(PATH_MAX1024)
157 pathconf_row(PIPE_BUF512)
158 pathconf_row(SYMLINK_MAX1024)
159
160 posix2_pathconf_row(SYMLINKS){ "_POSIX2_" "SYMLINKS", PATHCONF, 10 },
161
162 constant_row(_POSIX2_CHARCLASS_NAME_MAX14)
163 constant_row(_XOPEN_IOV_MAX16)
164 constant_row(_XOPEN_NAME_MAX255)
165 constant_row(_XOPEN_PATH_MAX1024)
166
167 /* Extensions */
168 sysconf_row(PHYS_PAGES)
169 sysconf_row(AVPHYS_PAGES)
170 sysconf_row(NPROCESSORS_CONF)
171 sysconf_row(NPROCESSORS_ONLN)
172
173 { NULL((void *)0) }
174};
175
176/*
177 * Lots of names have a leading "_POSIX_", so put them in a table with
178 * that prefix trimmed
179 */
180const char uposix_prefix[] = "_POSIX_";
181const struct conf_variable uposix_conf_table[] =
182{
183 /* POSIX.1 Maximum Values */
184 posix_constant_row(CLOCKRES_MIN)
185
186 /* POSIX.1 Minimum Values */
187 /*posix_constant_row(AIO_LISTIO_MAX)*/
188 /*posix_constant_row(AIO_MAX)*/
189 posix_constant_row(ARG_MAX(512 * 1024))
190 posix_constant_row(CHILD_MAX80)
191 /*posix_constant_row(DELAYTIMER_MAX)*/
192 posix_constant_row(HOST_NAME_MAX255)
193 posix_constant_row(LINK_MAX32767)
194 posix_constant_row(LOGIN_NAME_MAX32)
195 posix_constant_row(MAX_CANON255)
196 posix_constant_row(MAX_INPUT255)
197 /*posix_constant_row(MQ_OPEN_MAX)*/
198 /*posix_constant_row(MQ_PRIO_MAX)*/
199 posix_constant_row(NAME_MAX255)
200 posix_constant_row(NGROUPS_MAX16)
201 posix_constant_row(OPEN_MAX64)
202 posix_constant_row(PATH_MAX1024)
203 posix_constant_row(PIPE_BUF512)
204 posix_constant_row(RE_DUP_MAX255)
205 /*posix_constant_row(RTSIG_MAX)*/
206 posix_constant_row(SEM_NSEMS_MAX)
207 posix_constant_row(SEM_VALUE_MAX(2147483647 *2U +1U))
208 /*posix_constant_row(SIGQUEUE_MAX)*/
209 posix_constant_row(SSIZE_MAX9223372036854775807L)
210 /*posix_constant_row(SS_REPL_MAX)*/
211 posix_constant_row(STREAM_MAX)
212 posix_constant_row(SYMLINK_MAX1024)
213 posix_constant_row(SYMLOOP_MAX32)
214 posix_constant_row(THREAD_DESTRUCTOR_ITERATIONS)
215 posix_constant_row(THREAD_KEYS_MAX)
216 posix_constant_row(THREAD_THREADS_MAX)
217 /*posix_constant_row(TIMER_MAX)*/
218 posix_constant_row(TTY_NAME_MAX260)
219 posix_constant_row(TZNAME_MAX)
220
221 /* POSIX.1 Configurable System Variables */
222 sysconf_row(JOB_CONTROL)
223 sysconf_row(SAVED_IDS)
224 sysconf_row(VERSION)
225 sysconf_row(FSYNC)
226 sysconf_row(MONOTONIC_CLOCK)
227 sysconf_row(THREAD_SAFE_FUNCTIONS)
228 sysconf_row(ADVISORY_INFO)
229 sysconf_row(BARRIERS)
230 sysconf_row(ASYNCHRONOUS_IO)
231 sysconf_row(CLOCK_SELECTION)
232 sysconf_row(CPUTIME)
233 sysconf_row(IPV6)
234 sysconf_row(MAPPED_FILES)
235 sysconf_row(MEMLOCK)
236 sysconf_row(MEMLOCK_RANGE)
237 sysconf_row(MEMORY_PROTECTION)
238 sysconf_row(MESSAGE_PASSING)
239 sysconf_row(PRIORITIZED_IO)
240 sysconf_row(PRIORITY_SCHEDULING)
241 sysconf_row(RAW_SOCKETS)
242 sysconf_row(READER_WRITER_LOCKS)
243 sysconf_row(REALTIME_SIGNALS)
244 sysconf_row(REGEXP)
245 sysconf_row(SEMAPHORES)
246 sysconf_row(SHARED_MEMORY_OBJECTS)
247 sysconf_row(SHELL)
248 sysconf_row(SPAWN)
249 sysconf_row(SPIN_LOCKS)
250 sysconf_row(SPORADIC_SERVER)
251 sysconf_row(SS_REPL_MAX)
252 sysconf_row(SYNCHRONIZED_IO)
253 sysconf_row(THREAD_ATTR_STACKADDR)
254 sysconf_row(THREAD_ATTR_STACKSIZE)
255 sysconf_row(THREAD_CPUTIME)
256 sysconf_row(THREAD_PRIO_INHERIT)
257 sysconf_row(THREAD_PRIO_PROTECT)
258 sysconf_row(THREAD_PRIORITY_SCHEDULING)
259 sysconf_row(THREAD_PROCESS_SHARED)
260 sysconf_row(THREAD_ROBUST_PRIO_INHERIT)
261 sysconf_row(THREAD_SPORADIC_SERVER)
262 sysconf_row(THREADS)
263 sysconf_row(TIMEOUTS)
264 sysconf_row(TIMERS)
265 sysconf_row(TRACE)
266 sysconf_row(TRACE_EVENT_FILTER)
267 sysconf_row(TRACE_EVENT_NAME_MAX)
268 sysconf_row(TRACE_INHERIT)
269 sysconf_row(TRACE_LOG)
270 sysconf_row(TRACE_NAME_MAX)
271 sysconf_row(TRACE_SYS_MAX)
272 sysconf_row(TRACE_USER_EVENT_MAX)
273 sysconf_row(TYPED_MEMORY_OBJECTS)
274
275 /*
276 * If new compilation specification are added (V8_*?) then add them
277 * to the compilation_specs array below too
278 */
279 sysconf_row(V7_ILP32_OFF32)
280 sysconf_row(V7_ILP32_OFFBIG)
281 sysconf_row(V7_LP64_OFF64)
282 sysconf_row(V7_LPBIG_OFFBIG)
283 sysconf_row(V6_ILP32_OFF32)
284 sysconf_row(V6_ILP32_OFFBIG)
285 sysconf_row(V6_LP64_OFF64)
286 sysconf_row(V6_LPBIG_OFFBIG)
287
288 /* POSIX.1 Configurable Path Variables */
289 pathconf_row(CHOWN_RESTRICTED)
290 pathconf_row(NO_TRUNC)
291 pathconf_row(VDISABLE)
292 pathconf_row(ASYNC_IO)
293 pathconf_row(PRIO_IO)
294 pathconf_row(SYNC_IO)
295 pathconf_row(TIMESTAMP_RESOLUTION)
296
297 { NULL((void *)0) }
298};
299
300/*
301 * Then there are the "POSIX_*" values
302 */
303const char posix_prefix[] = "POSIX_";
304const struct conf_variable posix_conf_table[] =
305{
306 pathconf_row(ALLOC_SIZE_MIN)
307 pathconf_row(REC_INCR_XFER_SIZE)
308 pathconf_row(REC_MAX_XFER_SIZE)
309 pathconf_row(REC_MIN_XFER_SIZE)
310 pathconf_row(REC_XFER_ALIGN)
311
312 posix_confstr_row(V7_ILP32_OFF32_CFLAGS)
313 posix_confstr_row(V7_ILP32_OFF32_LDFLAGS)
314 posix_confstr_row(V7_ILP32_OFF32_LIBS)
315 posix_confstr_row(V7_ILP32_OFFBIG_CFLAGS)
316 posix_confstr_row(V7_ILP32_OFFBIG_LDFLAGS)
317 posix_confstr_row(V7_ILP32_OFFBIG_LIBS)
318 posix_confstr_row(V7_LP64_OFF64_CFLAGS)
319 posix_confstr_row(V7_LP64_OFF64_LDFLAGS)
320 posix_confstr_row(V7_LP64_OFF64_LIBS)
321 posix_confstr_row(V7_LPBIG_OFFBIG_CFLAGS)
322 posix_confstr_row(V7_LPBIG_OFFBIG_LDFLAGS)
323 posix_confstr_row(V7_LPBIG_OFFBIG_LIBS)
324 posix_confstr_row(V7_THREADS_CFLAGS)
325 posix_confstr_row(V7_THREADS_LDFLAGS)
326 posix_confstr_row(V7_WIDTH_RESTRICTED_ENVS)
327 posix_confstr_row(V6_ILP32_OFF32_CFLAGS)
328 posix_confstr_row(V6_ILP32_OFF32_LDFLAGS)
329 posix_confstr_row(V6_ILP32_OFF32_LIBS)
330 posix_confstr_row(V6_ILP32_OFFBIG_CFLAGS)
331 posix_confstr_row(V6_ILP32_OFFBIG_LDFLAGS)
332 posix_confstr_row(V6_ILP32_OFFBIG_LIBS)
333 posix_confstr_row(V6_LP64_OFF64_CFLAGS)
334 posix_confstr_row(V6_LP64_OFF64_LDFLAGS)
335 posix_confstr_row(V6_LP64_OFF64_LIBS)
336 posix_confstr_row(V6_LPBIG_OFFBIG_CFLAGS)
337 posix_confstr_row(V6_LPBIG_OFFBIG_LDFLAGS)
338 posix_confstr_row(V6_LPBIG_OFFBIG_LIBS)
339 posix_confstr_row(V6_WIDTH_RESTRICTED_ENVS)
340
341 { NULL((void *)0) }
342};
343
344/*
345 * Finally, there are variables that are accepted with a prefix
346 * of either "_POSIX2_" or "POSIX2_"
347 */
348const char compat_posix2_prefix[] = "POSIX2_";
349const struct conf_variable compat_posix2_conf_table[] =
350{
351 /* Optional Facility Configuration Values */
352 compat_posix2_sysconf_row(VERSION)
353 compat_posix2_sysconf_row(C_BIND)
354 compat_posix2_sysconf_row(C_DEV)
355 compat_posix2_sysconf_row(CHAR_TERM)
356 compat_posix2_sysconf_row(FORT_DEV)
357 compat_posix2_sysconf_row(FORT_RUN)
358 compat_posix2_sysconf_row(LOCALEDEF)
359 compat_posix2_sysconf_row(SW_DEV)
360 compat_posix2_sysconf_row(UPE)
361
362 /* Utility Limit Minimum Values */
363 compat_posix2_constant_row(BC_BASE_MAX2147483647)
364 compat_posix2_constant_row(BC_DIM_MAX65535)
365 compat_posix2_constant_row(BC_SCALE_MAX2147483647)
366 compat_posix2_constant_row(BC_STRING_MAX2147483647)
367 compat_posix2_constant_row(COLL_WEIGHTS_MAX2)
368 compat_posix2_constant_row(EXPR_NEST_MAX32)
369 compat_posix2_constant_row(LINE_MAX2048)
370 compat_posix2_constant_row(RE_DUP_MAX255)
371
372 { NULL((void *)0) }
373};
374
375#undef constant_row
376#undef sysconf_row
377#undef pathconf_row
378#undef confstr_row
379#undef posix_constant_row
380#undef posix_confstr_row
381#undef compat_posix2_sysconf_row
382#undef compat_posix2_constant_row
383
384
385/*
386 * What values are possibly accepted by the -v option?
387 * These are implied to have a prefix of posix_prefix
388 */
389const char *compilation_specs[] = {
390 "V7_ILP32_OFF32",
391 "V7_ILP32_OFFBIG",
392 "V7_LP64_OFF64",
393 "V7_LPBIG_OFFBIG",
394 "V6_ILP32_OFF32",
395 "V6_ILP32_OFFBIG",
396 "V6_LP64_OFF64",
397 "V6_LPBIG_OFFBIG",
398 NULL((void *)0)
399};
400
401int
402main(int argc, char *argv[])
403{
404 int ch;
405 const struct conf_variable *cp;
406
407 long val;
408 size_t slen;
409 char * sval;
410
411 while ((ch = getopt(argc, argv, "lLv:")) != -1) {
1
Assuming the condition is false
2
Loop condition is false. Execution continues on line 428
412 switch (ch) {
413 case 'l': /* nonstandard: list system variables */
414 list_var(0);
415 return (0);
416 case 'L': /* nonstandard: list path variables */
417 list_var(1);
418 return (0);
419 case 'v':
420 if (! compilation_spec_valid(optarg))
421 errx(1, "%s: unknown specification", optarg);
422 break;
423 case '?':
424 default:
425 usage();
426 }
427 }
428 argc -= optind;
429 argv += optind;
430
431 if (argc < 1 || argc > 2)
3
Assuming 'argc' is >= 1
4
Assuming 'argc' is <= 2
5
Taking false branch
432 usage();
433
434 /* pick a table based on a possible prefix */
435 if (strncmp(*argv, uposix_prefix, sizeof(uposix_prefix) - 1) == 0) {
6
Taking true branch
436 cp = uposix_conf_table;
437 slen = sizeof(uposix_prefix) - 1;
438 } else if (strncmp(*argv, posix_prefix,
439 sizeof(posix_prefix) - 1) == 0) {
440 cp = posix_conf_table;
441 slen = sizeof(posix_prefix) - 1;
442 } else {
443 cp = conf_table;
444 slen = 0;
445 }
446
447 /* scan the table */
448 for (; cp->name != NULL((void *)0); cp++)
7
Assuming field 'name' is not equal to NULL
8
Loop condition is true. Entering loop body
449 if (strcmp(*argv + slen, cp->name) == 0)
9
Taking true branch
450 break;
10
Execution continues on line 457
451
452 /*
453 * If no match, then make a final check against
454 * compat_posix2_conf_table, with special magic to accept/skip
455 * a leading underbar
456 */
457 slen = argv[0][0] == '_';
458 if (cp->name
10.1
Field 'name' is not equal to NULL
== NULL((void *)0) && strncmp(*argv + slen, compat_posix2_prefix,
459 sizeof(compat_posix2_prefix) - 1) == 0) {
460 slen += sizeof(compat_posix2_prefix) - 1;
461 for (cp = compat_posix2_conf_table; cp->name != NULL((void *)0); cp++) {
462 if (strcmp(*argv + slen, cp->name) == 0)
463 break;
464 }
465 }
466
467 if (cp->name
10.2
Field 'name' is not equal to NULL
== NULL((void *)0))
11
Taking false branch
468 errx(1, "%s: unknown variable", *argv);
469
470 if (cp->type == PATHCONF) {
12
Assuming field 'type' is not equal to PATHCONF
13
Taking false branch
471 if (argc != 2) usage();
472 } else {
473 if (argc != 1) usage();
14
Assuming 'argc' is equal to 1
15
Taking false branch
474 }
475
476 switch (cp->type) {
16
Control jumps to 'case CONFSTR:' at line 483
477 case CONSTANT:
478 if (pledge("stdio", NULL((void *)0)) == -1)
479 err(1, "pledge");
480 printf("%ld\n", cp->value);
481 break;
482
483 case CONFSTR:
484 if (pledge("stdio", NULL((void *)0)) == -1)
17
Assuming the condition is false
18
Taking false branch
485 err(1, "pledge");
486 errno(*__errno()) = 0;
487 if ((slen = confstr(cp->value, NULL((void *)0), 0)) == 0) {
19
Assuming the condition is false
20
Taking false branch
488 if (errno(*__errno()) != 0)
489 err(1, NULL((void *)0));
490
491 printf("undefined\n");
492 } else {
493 if ((sval = malloc(slen)) == NULL((void *)0))
21
Memory is allocated
22
Assuming the condition is false
23
Taking false branch
494 err(1, NULL((void *)0));
495
496 confstr(cp->value, sval, slen);
497 printf("%s\n", sval);
498 }
499 break;
24
Execution continues on line 532
500
501 case SYSCONF:
502 if (pledge("stdio inet ps vminfo", NULL((void *)0)) == -1)
503 err(1, "pledge");
504 errno(*__errno()) = 0;
505 if ((val = sysconf(cp->value)) == -1) {
506 if (errno(*__errno()) != 0)
507 err(1, NULL((void *)0));
508
509 printf("undefined\n");
510 } else {
511 printf("%ld\n", val);
512 }
513 break;
514
515 case PATHCONF:
516 if (unveil(argv[1], "r") == -1)
517 err(1, "unveil %s", argv[1]);
518 if (pledge("stdio rpath", NULL((void *)0)) == -1)
519 err(1, "pledge");
520 errno(*__errno()) = 0;
521 if ((val = pathconf(argv[1], cp->value)) == -1) {
522 if (errno(*__errno()) != 0)
523 err(1, "%s", argv[1]);
524
525 printf("undefined\n");
526 } else {
527 printf("%ld\n", val);
528 }
529 break;
530 }
531
532 return ferror(stdout)(!__isthreaded ? ((((&__sF[1]))->_flags & 0x0040) !=
0) : (ferror)((&__sF[1])))
;
25
Potential leak of memory pointed to by 'sval'
533}
534
535
536static void __dead__attribute__((__noreturn__))
537usage(void)
538{
539 extern char *__progname;
540
541 (void)fprintf(stderr(&__sF[2]),
542 "usage: %s [-Ll] [-v specification] name [pathname]\n",
543 __progname);
544 exit(1);
545}
546
547static void
548list_var(int do_pathconf)
549{
550 const struct conf_variable *cp;
551
552 for (cp = uposix_conf_table; cp->name != NULL((void *)0); cp++)
553 if ((cp->type == PATHCONF) == do_pathconf)
554 printf("%s%s\n", uposix_prefix, cp->name);
555 for (cp = posix_conf_table; cp->name != NULL((void *)0); cp++)
556 if ((cp->type == PATHCONF) == do_pathconf)
557 printf("%s%s\n", posix_prefix, cp->name);
558 for (cp = conf_table; cp->name != NULL((void *)0); cp++)
559 if ((cp->type == PATHCONF) == do_pathconf)
560 printf("%s\n", cp->name);
561 for (cp = compat_posix2_conf_table; cp->name != NULL((void *)0); cp++)
562 if ((cp->type == PATHCONF) == do_pathconf)
563 printf("_%s%s\n", compat_posix2_prefix, cp->name);
564}
565
566static int
567compilation_spec_valid(const char *spec)
568{
569 const char **sp;
570 const struct conf_variable *cp;
571
572 if (strncmp(spec, posix_prefix, sizeof(posix_prefix) - 1) != 0)
573 return (0);
574
575 spec += sizeof(posix_prefix) - 1;
576 for (sp = compilation_specs; *sp != NULL((void *)0); sp++)
577 if (strcmp(spec, *sp) == 0)
578 break;
579 if (*sp == NULL((void *)0))
580 return (0);
581
582 for (cp = uposix_conf_table; cp->name != NULL((void *)0); cp++)
583 if (strcmp(spec, cp->name) == 0 && cp->type == SYSCONF)
584 return (sysconf(cp->value) != -1);
585
586 return (0);
587}