Bug Summary

File:src/usr.sbin/tcpdump/print-llc.c
Warning:line 275, column 3
Value stored to 'p' 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 print-llc.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/tcpdump/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.sbin/tcpdump/../../sbin/pfctl -I /usr/src/usr.sbin/tcpdump/../hostapd -I /usr/src/usr.sbin/tcpdump/../../lib/libpcap -D CSLIP -D PPP -D HAVE_FDDI -D ETHER_SERVICE -D HAVE_ETHER_NTOHOST -D INET6 -I /usr/src/usr.sbin/tcpdump/../../sbin/pfctl -D FAKE_PF_KERNEL -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/tcpdump/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/tcpdump/print-llc.c
1/* $OpenBSD: print-llc.c,v 1.22 2020/01/24 22:46:37 procter Exp $ */
2
3/*
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
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 * Code by Matt Thomas, Digital Equipment Corporation
24 * with an awful lot of hacking by Jeffrey Mogul, DECWRL
25 */
26
27#include <sys/time.h>
28
29#include <netinet/in.h>
30
31#include <ctype.h>
32#include <netdb.h>
33#include <signal.h>
34#include <stdio.h>
35#include <string.h>
36
37#include "interface.h"
38#include "addrtoname.h"
39#include "extract.h" /* must come after interface.h */
40#include "ethertype.h"
41
42#include "llc.h"
43
44static struct tok cmd2str[] = {
45 { LLC_UI0x03, "ui" },
46 { LLC_TEST0xe3, "test" },
47 { LLC_XID0xaf, "xid" },
48 { LLC_UA0x63, "ua" },
49 { LLC_DISC0x43, "disc" },
50 { LLC_DM0x0f, "dm" },
51 { LLC_SABME0x6f, "sabme" },
52 { LLC_FRMR0x87, "frmr" },
53 { 0, NULL((void *)0) }
54};
55
56/*
57 * Returns non-zero IFF it succeeds in printing the header
58 */
59int
60llc_print(const u_char *p, u_int length, u_int caplen,
61 const u_char *esrc, const u_char *edst)
62{
63 struct llc llc;
64 u_short et;
65#if 0
66 u_short control;
67#endif
68 int ret;
69
70 if (caplen < 3) {
71 printf("[|llc]");
72 default_print((u_char *)p, caplen);
73 return(0);
74 }
75
76 /* Watch out for possible alignment problems */
77 memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc))((caplen)>(sizeof(llc))?(sizeof(llc)):(caplen)));
78
79 if (llc.ssap == LLCSAP_GLOBAL0xff && llc.dsap == LLCSAP_GLOBAL0xff) {
80 ipx_print(p, length);
81 return (1);
82 }
83#ifdef notyet
84 else if (p[0] == 0xf0 && p[1] == 0xf0)
85 netbios_print(p, length);
86#endif
87 if (llc.ssap == LLCSAP_ISONS0xfe && llc.dsap == LLCSAP_ISONS0xfe
88 && llc.llcuictl.snap.snap_ui == LLC_UI0x03) {
89 isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst);
90 return (1);
91 }
92
93 if (llc.ssap == LLCSAP_SNAP0xaa && llc.dsap == LLCSAP_SNAP0xaa
94 && llc.llcuictl.snap.snap_ui == LLC_UI0x03) {
95 if (caplen < sizeof(llc)) {
96 printf("[|llc-snap]");
97 default_print((u_char *)p, caplen);
98 return (0);
99 }
100
101 /* Cisco Discovery Protocol - SNAP & ether type 0x2000 */
102 if (llc.ethertypectl.snap_ether.snap_ethertype[0] == 0x20 && llc.ethertypectl.snap_ether.snap_ethertype[1] == 0x00) {
103 cdp_print(p, length, caplen, 8);
104 return (1);
105 }
106 /* Shared Spanning Tree Protocol - SNAP & ether type 0x010b */
107 if (llc.ethertypectl.snap_ether.snap_ethertype[0] == 0x01 && llc.ethertypectl.snap_ether.snap_ethertype[1] == 0x0b) {
108 stp_print(p, length);
109 return (1);
110 }
111
112 if (vflag)
113 printf("snap %s ", protoid_string(llc.llcpictl.snap.snap_pi));
114
115 caplen -= sizeof(llc);
116 length -= sizeof(llc);
117 p += sizeof(llc);
118
119 /* This is an encapsulated Ethernet packet */
120 et = EXTRACT_16BITS(&llc.ethertype[0])((u_int16_t)*((const u_int8_t *)(&llc.ctl.snap_ether.snap_ethertype
[0]) + 0) << 8 | (u_int16_t)*((const u_int8_t *)(&llc
.ctl.snap_ether.snap_ethertype[0]) + 1))
;
121
122 /*
123 * Some protocols have special handling if they are 802.3
124 * SNAP encapsulated vs vers II encapsulated. Handle
125 * those special protocols here, and hand the rest to
126 * print-ether.c so we don't have to duplicate
127 * all that code here.
128 */
129 switch (et) {
130 case ETHERTYPE_ATALK0x809b:
131 atalk_print(p, length);
132 ret = 1;
133 break;
134 default:
135 ret = ether_encap_print(et, p, length, caplen);
136 break;
137 }
138
139 if (ret)
140 return (ret);
141 }
142
143 if (llc.ssap == LLCSAP_8021D0x42 && llc.dsap == LLCSAP_8021D0x42) {
144 stp_print(p, length);
145 return (1);
146 }
147
148#if 0
149 if (llc.ssap == 0xf0 && llc.dsap == 0xf0) {
150 /*
151 * we don't actually have a full netbeui parser yet, but the
152 * smb parser can handle many smb-in-netbeui packets, which
153 * is very useful, so we call that
154 */
155
156 /*
157 * Skip the DSAP and LSAP.
158 */
159 p += 2;
160 length -= 2;
161 caplen -= 2;
162
163 /*
164 * OK, what type of LLC frame is this? The length
165 * of the control field depends on that - S or I
166 * frames have a two-byte control field, and U frames
167 * have a one-byte control field.
168 */
169 if ((llc.llcuctl.u_ctl & LLC_U_FMT3) == LLC_U_FMT3) {
170 control = llc.llcuctl.u_ctl;
171 p += 1;
172 length -= 1;
173 caplen -= 1;
174 } else {
175 control = llc.llcisctl.is_ctl;
176 p += 2;
177 length -= 2;
178 caplen -= 2;
179 }
180
181 netbeui_print(control, p, p + min(caplen, length)((caplen)>(length)?(length):(caplen)));
182 return (1);
183 }
184#endif
185
186 if ((llc.ssap & ~LLC_GSAP1) == llc.dsap) {
187 if (eflag)
188 printf("%s ", llcsap_string(llc.dsap));
189 else
190 printf("%s > %s %s ",
191 etheraddr_string(esrc),
192 etheraddr_string(edst),
193 llcsap_string(llc.dsap));
194 } else {
195 if (eflag)
196 printf("%s > %s ",
197 llcsap_string(llc.ssap & ~LLC_GSAP1),
198 llcsap_string(llc.dsap));
199 else
200 printf("%s %s > %s %s ",
201 etheraddr_string(esrc),
202 llcsap_string(llc.ssap & ~LLC_GSAP1),
203 etheraddr_string(edst),
204 llcsap_string(llc.dsap));
205 }
206
207 if ((llc.llcuctl.u_ctl & LLC_U_FMT3) == LLC_U_FMT3) {
208 const char *m;
209 char f;
210 m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu)((llc.ctl.u_ctl) & 0xef));
211 switch ((llc.ssap & LLC_GSAP1) | (llc.llcuctl.u_ctl & LLC_U_POLL0x10)) {
212 case 0: f = 'C'; break;
213 case LLC_GSAP1: f = 'R'; break;
214 case LLC_U_POLL0x10: f = 'P'; break;
215 case LLC_GSAP1|LLC_U_POLL0x10: f = 'F'; break;
216 default: f = '?'; break;
217 }
218
219 printf("%s/%c", m, f);
220
221 if (caplen < 6) {
222 default_print_unaligned(p, caplen);
223 return (0);
224 }
225 p += 3;
226 length -= 3;
227 caplen -= 3;
228
229 if ((llc.llcuctl.u_ctl & ~LLC_U_POLL0x10) == LLC_XID0xaf) {
230 if (*p == LLC_XID_FI0x81) {
231 printf(": %02x %02x", p[1], p[2]);
232 p += 3;
233 length -= 3;
234 caplen -= 3;
235 }
236 }
237
238#if 0
239 if (!strcmp(m,"ui") && f=='C') {
240 /*
241 * we don't have a proper ipx decoder yet, but there
242 * is a partial one in the smb code
243 */
244 ipx_netbios_print(p,p+min(caplen,length)((caplen)>(length)?(length):(caplen)));
245 }
246#endif
247
248 } else {
249 char f;
250 if (caplen < 4) {
251 default_print_unaligned(p, caplen);
252 return (0);
253 }
254 llc.llcisctl.is_ctl = ntohs(llc.llcis)(__uint16_t)(__builtin_constant_p(llc.ctl.is_ctl) ? (__uint16_t
)(((__uint16_t)(llc.ctl.is_ctl) & 0xffU) << 8 | ((__uint16_t
)(llc.ctl.is_ctl) & 0xff00U) >> 8) : __swap16md(llc
.ctl.is_ctl))
;
255 switch ((llc.ssap & LLC_GSAP1) | (llc.llcuctl.u_ctl & LLC_U_POLL0x10)) {
256 case 0: f = 'C'; break;
257 case LLC_GSAP1: f = 'R'; break;
258 case LLC_U_POLL0x10: f = 'P'; break;
259 case LLC_GSAP1|LLC_U_POLL0x10: f = 'F'; break;
260 default: f = '?'; break;
261 }
262
263 if ((llc.llcuctl.u_ctl & LLC_S_FMT1) == LLC_S_FMT1) {
264 static char *llc_s[] = { "rr", "rej", "rnr", "03" };
265 printf("%s (r=%d,%c)",
266 llc_s[LLC_S_CMD(llc.llcis)(((llc.ctl.is_ctl) >> 10) & 0x03)],
267 LLC_IS_NR(llc.llcis)(((llc.ctl.is_ctl) >> 1) & 0x7f),
268 f);
269 } else {
270 printf("I (s=%d,r=%d,%c)",
271 LLC_I_NS(llc.llcis)(((llc.ctl.is_ctl) >> 9) & 0x7f),
272 LLC_IS_NR(llc.llcis)(((llc.ctl.is_ctl) >> 1) & 0x7f),
273 f);
274 }
275 p += 4;
Value stored to 'p' is never read
276 length -= 4;
277 caplen -= 4;
278 }
279 printf(" len=%d", length);
280 return(1);
281}