Bug Summary

File:src/sbin/dhclient/parse.c
Warning:line 93, column 6
Value stored to 'token' is never read

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 parse.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/sbin/dhclient/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/sbin/dhclient/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/sbin/dhclient/parse.c
1/* $OpenBSD: parse.c,v 1.83 2019/07/22 17:20:06 krw Exp $ */
2
3/* Common parser code for dhcpd and dhclient. */
4
5/*
6 * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
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. Neither the name of The Internet Software Consortium nor the names
19 * of its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * This software has been written for the Internet Software Consortium
37 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
38 * Enterprises. To learn more about the Internet Software Consortium,
39 * see ``http://www.vix.com/isc''. To learn more about Vixie
40 * Enterprises, see ``http://www.vix.com''.
41 */
42
43#include <sys/queue.h>
44#include <sys/socket.h>
45
46#include <net/if.h>
47
48#include <netinet/in.h>
49#include <netinet/if_ether.h>
50
51#include <errno(*__errno()).h>
52#include <limits.h>
53#include <signal.h>
54#include <stdio.h>
55#include <stdlib.h>
56#include <stdint.h>
57#include <string.h>
58#include <syslog.h>
59#include <unistd.h>
60#include <vis.h>
61
62#include "dhcp.h"
63#include "dhcpd.h"
64#include "dhctoken.h"
65#include "log.h"
66
67/*
68 * Skip to the semicolon ending the current statement. If we encounter
69 * braces, the matching closing brace terminates the statement. If we
70 * encounter a right brace but haven't encountered a left brace, return
71 * leaving the brace in the token buffer for the caller. If we see a
72 * semicolon and haven't seen a left brace, return. This lets us skip
73 * over:
74 *
75 * statement;
76 * statement foo bar { }
77 * statement foo bar { statement { } }
78 * statement}
79 *
80 * ...et cetera.
81 */
82void
83skip_to_semi(FILE *cfile)
84{
85 int token;
86 int brace_count = 0;
87
88 do {
89 token = peek_token(NULL((void *)0), cfile);
90 if (token == '}') {
91 if (brace_count > 0) {
92 if (--brace_count == 0) {
93 token = next_token(NULL((void *)0), cfile);
Value stored to 'token' is never read
94 return;
95 }
96 } else
97 return;
98 } else if (token == '{') {
99 brace_count++;
100 } else if (token == ';' && brace_count == 0) {
101 token = next_token(NULL((void *)0), cfile);
102 return;
103 }
104 token = next_token(NULL((void *)0), cfile);
105 } while (token != EOF(-1));
106}
107
108int
109parse_semi(FILE *cfile)
110{
111 int token;
112
113 token = next_token(NULL((void *)0), cfile);
114 if (token == ';')
115 return 1;
116
117 parse_warn("expecting semicolon.");
118 skip_to_semi(cfile);
119
120 return 0;
121}
122
123int
124parse_string(FILE *cfile, char **string)
125{
126 static char unvisbuf[1500];
127 char *val;
128 int i, token;
129
130 token = next_token(&val, cfile);
131 if (token == TOK_STRING262) {
132 i = strnunvis(unvisbuf, val, sizeof(unvisbuf));
133 if (i >= 0) {
134 *string = strdup(unvisbuf);
135 if (*string == NULL((void *)0))
136 fatal("strdup(unvisbuf)");
137 return 1;
138 }
139 }
140
141 parse_warn("expecting string.");
142
143 if (token != ';')
144 skip_to_semi(cfile);
145
146 return 0;
147}
148
149/*
150 * cidr :== ip-address "/" bit-count
151 * ip-address :== NUMBER [ DOT NUMBER [ DOT NUMBER [ DOT NUMBER ] ] ]
152 * bit-count :== 0..32
153 */
154int
155parse_cidr(FILE *cfile, unsigned char *cidr)
156{
157 uint8_t buf[5];
158 const char *errstr;
159 char *val;
160 long long numval;
161 unsigned int i;
162 int token;
163
164 memset(buf, 0, sizeof(buf));
165 i = 1; /* Last four octets hold subnet, first octet the # of bits. */
166 do {
167 token = next_token(&val, cfile);
168 if (i == 0)
169 numval = strtonum(val, 0, 32, &errstr);
170 else
171 numval = strtonum(val, 0, UINT8_MAX0xff, &errstr);
172 if (errstr != NULL((void *)0))
173 break;
174 buf[i++] = numval;
175 if (i == 1) {
176 memcpy(cidr, buf, sizeof(buf)); /* XXX Need cidr_t */
177 return 1;
178 }
179 token = next_token(NULL((void *)0), cfile);
180 if (token == '/')
181 i = 0;
182 if (i == sizeof(buf))
183 break;
184 } while (token == '.' || token == '/');
185
186 parse_warn("expecting IPv4 CIDR block.");
187
188 if (token != ';')
189 skip_to_semi(cfile);
190
191 return 0;
192}
193
194int
195parse_ip_addr(FILE *cfile, struct in_addr *addr)
196{
197 struct in_addr buf;
198 const char *errstr;
199 char *val;
200 long long numval;
201 unsigned int i;
202 int token;
203
204 i = 0;
205 do {
206 token = next_token(&val, cfile);
207 numval = strtonum(val, 0, UINT8_MAX0xff, &errstr);
208 if (errstr != NULL((void *)0))
209 break;
210 ((uint8_t *)&buf)[i++] = numval;
211 if (i == sizeof(buf)) {
212 memcpy(addr, &buf, sizeof(*addr));
213 return 1;
214 }
215 token = next_token(NULL((void *)0), cfile);
216 } while (token == '.');
217
218 parse_warn("expecting IPv4 address.");
219
220 if (token != ';')
221 skip_to_semi(cfile);
222
223 return 0;
224}
225
226int
227parse_boolean(FILE *cfile, unsigned char *buf)
228{
229 char *val;
230 int token;
231
232 token = next_token(&val, cfile);
233 if (is_identifier(token)((token) >= 257 && (token) != 262 && (token
) != 263 && (token) != (-1))
!= 0) {
234 if (strcasecmp(val, "true") == 0 ||
235 strcasecmp(val, "on") == 0) {
236 buf[0] = 1;
237 return 1;
238 }
239 if (strcasecmp(val, "false") == 0 ||
240 strcasecmp(val, "off") == 0) {
241 buf[0] = 0;
242 return 1;
243 }
244 }
245
246 parse_warn("expecting boolean.");
247 if (token != ';')
248 skip_to_semi(cfile);
249
250 return 0;
251}
252
253int
254parse_number(FILE *cfile, long long *number, long long low, long long high)
255{
256 const char *errstr;
257 char *val, *msg;
258 int rslt, token;
259 long long numval;
260
261 token = next_token(&val, cfile);
262
263 numval = strtonum(val, low, high, &errstr);
264 if (errstr == NULL((void *)0)) {
265 *number = numval;
266 return 1;
267 }
268
269 rslt = asprintf(&msg, "expecting integer between %lld and %lld", low,
270 high);
271 if (rslt != -1) {
272 parse_warn(msg);
273 free(msg);
274 }
275
276 if (token != ';')
277 skip_to_semi(cfile);
278
279 return 0;
280}
281
282void
283parse_warn(char *msg)
284{
285 static char spaces[81];
286 unsigned int i;
287
288 log_warnx("%s: %s line %d: %s", log_procname, tlname, lexline, msg);
289 log_warnx("%s: %s", log_procname, token_line);
290 if ((unsigned int)lexchar < sizeof(spaces)) {
291 memset(spaces, 0, sizeof(spaces));
292 for (i = 0; (int)i < lexchar - 1; i++) {
293 if (token_line[i] == '\t')
294 spaces[i] = '\t';
295 else
296 spaces[i] = ' ';
297 }
298 log_warnx("%s: %s^", log_procname, spaces);
299 }
300}