Bug Summary

File:src/lib/libpcap/etherent.c
Warning:line 106, column 7
Assigned value is garbage or undefined

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 etherent.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 -fhalf-no-semantic-interposition -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/lib/libpcap/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -I /usr/src/lib/libpcap -D yylval=pcap_yylval -D HAVE_SYS_IOCCOM_H -D HAVE_SYS_SOCKIO_H -D HAVE_ETHER_HOSTTON -D HAVE_STRERROR -D HAVE_SOCKADDR_SA_LEN -D LBL_ALIGN -D HAVE_IFADDRS_H -D INET6 -D HAVE_BSD_IEEE80211 -D PIC -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libpcap/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/lib/libpcap/etherent.c
1/* $OpenBSD: etherent.c,v 1.9 2015/11/17 21:39:23 mmcc Exp $ */
2
3/*
4 * Copyright (c) 1990, 1993, 1994, 1995, 1996
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24#include <sys/types.h>
25
26#include <ctype.h>
27#include <stdio.h>
28#include <string.h>
29
30#include "pcap-int.h"
31
32#include <pcap-namedb.h>
33#ifdef HAVE_OS_PROTO_H
34#include "os-proto.h"
35#endif
36
37static __inline int xdtoi(int);
38static __inline int skip_space(FILE *);
39static __inline int skip_line(FILE *);
40
41/* Hex digit to integer. */
42static __inline int
43xdtoi(c)
44 int c;
45{
46 if (isdigit(c))
47 return c - '0';
48 else if (islower(c))
49 return c - 'a' + 10;
50 else
51 return c - 'A' + 10;
52}
53
54static __inline int
55skip_space(f)
56 FILE *f;
57{
58 int c;
59
60 do {
61 c = getc(f)(!__isthreaded ? (--(f)->_r < 0 ? __srget(f) : (int)(*(
f)->_p++)) : (getc)(f))
;
62 } while (isspace(c) && c != '\n');
63
64 return c;
65}
66
67static __inline int
68skip_line(f)
69 FILE *f;
70{
71 int c;
72
73 do
74 c = getc(f)(!__isthreaded ? (--(f)->_r < 0 ? __srget(f) : (int)(*(
f)->_p++)) : (getc)(f))
;
75 while (c != '\n' && c != EOF(-1));
76
77 return c;
78}
79
80struct pcap_etherent *
81pcap_next_etherent(FILE *fp)
82{
83 int c, d, i;
84 char *bp;
85 static struct pcap_etherent e;
86
87 memset((char *)&e, 0, sizeof(e));
88 do {
89 /* Find addr */
90 c = skip_space(fp);
91 if (c == '\n')
1
Taking false branch
92 continue;
93
94 /* If this is a comment, or first thing on line
95 cannot be etehrnet address, skip the line. */
96 if (!isxdigit(c)) {
2
Taking false branch
97 c = skip_line(fp);
98 continue;
99 }
100
101 /* must be the start of an address */
102 for (i = 0; i < 6; i += 1) {
3
Loop condition is true. Entering loop body
9
Loop condition is true. Entering loop body
103 d = xdtoi(c);
104 c = getc(fp)(!__isthreaded ? (--(fp)->_r < 0 ? __srget(fp) : (int)(
*(fp)->_p++)) : (getc)(fp))
;
4
'?' condition is false
10
'?' condition is false
105 if (isxdigit(c)) {
5
Taking false branch
11
Taking true branch
106 d <<= 4;
12
Assigned value is garbage or undefined
107 d |= xdtoi(c);
108 c = getc(fp)(!__isthreaded ? (--(fp)->_r < 0 ? __srget(fp) : (int)(
*(fp)->_p++)) : (getc)(fp))
;
109 }
110 e.addr[i] = d;
111 if (c != ':')
6
Assuming the condition is false
7
Taking false branch
112 break;
113 c = getc(fp)(!__isthreaded ? (--(fp)->_r < 0 ? __srget(fp) : (int)(
*(fp)->_p++)) : (getc)(fp))
;
8
'?' condition is false
114 }
115 if (c == EOF(-1))
116 break;
117
118 /* Must be whitespace */
119 if (!isspace(c)) {
120 c = skip_line(fp);
121 continue;
122 }
123 c = skip_space(fp);
124
125 /* hit end of line... */
126 if (c == '\n')
127 continue;
128
129 if (c == '#') {
130 c = skip_line(fp);
131 continue;
132 }
133
134 /* pick up name */
135 bp = e.name;
136 /* Use 'd' to prevent buffer overflow. */
137 d = sizeof(e.name) - 1;
138 do {
139 *bp++ = c;
140 c = getc(fp)(!__isthreaded ? (--(fp)->_r < 0 ? __srget(fp) : (int)(
*(fp)->_p++)) : (getc)(fp))
;
141 } while (!isspace(c) && c != EOF(-1) && --d > 0);
142 *bp = '\0';
143
144 /* Eat trailing junk */
145 if (c != '\n')
146 (void)skip_line(fp);
147
148 return &e;
149
150 } while (c != EOF(-1));
151
152 return (NULL((void *)0));
153}