Bug Summary

File:src/lib/libc/net/inet_net_ntop.c
Warning:line 131, column 2
Value stored to 'dst' 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 inet_net_ntop.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/lib/libc/obj -resource-dir /usr/local/lib/clang/13.0.0 -include namespace.h -I /usr/src/lib/libc/include -I /usr/src/lib/libc/hidden -D __LIBC__ -D APIWARN -D YP -I /usr/src/lib/libc/yp -I /usr/src/lib/libc -I /usr/src/lib/libc/gdtoa -I /usr/src/lib/libc/arch/amd64/gdtoa -D INFNAN_CHECK -D MULTIPLE_THREADS -D NO_FENV_H -D USE_LOCALE -I /usr/src/lib/libc -I /usr/src/lib/libc/citrus -D RESOLVSORT -D FLOATING_POINT -D PRINTF_WIDE_CHAR -D SCANF_WIDE_CHAR -D FUTEX -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libc/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/libc/net/inet_net_ntop.c
1/* $OpenBSD: inet_net_ntop.c,v 1.9 2019/07/03 03:24:04 deraadt Exp $ */
2
3/*
4 * Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org>
5 * Copyright (c) 1996 by Internet Software Consortium.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
12 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
13 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
14 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
18 * SOFTWARE.
19 */
20
21#include <sys/types.h>
22#include <sys/socket.h>
23#include <netinet/in.h>
24#include <arpa/inet.h>
25
26#include <errno(*__errno()).h>
27#include <stdio.h>
28#include <string.h>
29#include <stdlib.h>
30
31static char *inet_net_ntop_ipv4(const u_char *, int, char *, size_t);
32static char *inet_net_ntop_ipv6(const u_char *, int, char *, size_t);
33
34/*
35 * char *
36 * inet_net_ntop(af, src, bits, dst, size)
37 * convert network number from network to presentation format.
38 * generates CIDR style result always.
39 * return:
40 * pointer to dst, or NULL if an error occurred (check errno).
41 * author:
42 * Paul Vixie (ISC), July 1996
43 */
44char *
45inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
46{
47 switch (af) {
48 case AF_INET2:
49 return (inet_net_ntop_ipv4(src, bits, dst, size));
50 case AF_INET624:
51 return (inet_net_ntop_ipv6(src, bits, dst, size));
52 default:
53 errno(*__errno()) = EAFNOSUPPORT47;
54 return (NULL((void *)0));
55 }
56}
57
58/*
59 * static char *
60 * inet_net_ntop_ipv4(src, bits, dst, size)
61 * convert IPv4 network number from network to presentation format.
62 * generates CIDR style result always.
63 * return:
64 * pointer to dst, or NULL if an error occurred (check errno).
65 * note:
66 * network byte order assumed. this means 192.5.5.240/28 has
67 * 0x11110000 in its fourth octet.
68 * author:
69 * Paul Vixie (ISC), July 1996
70 */
71static char *
72inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
73{
74 char *odst = dst;
75 u_int m;
76 int b;
77 char *ep;
78 int advance;
79
80 ep = dst + size;
81 if (ep <= dst)
82 goto emsgsize;
83
84 if (bits < 0 || bits > 32) {
85 errno(*__errno()) = EINVAL22;
86 return (NULL((void *)0));
87 }
88 if (bits == 0) {
89 if (ep - dst < sizeof "0")
90 goto emsgsize;
91 *dst++ = '0';
92 *dst = '\0';
93 }
94
95 /* Format whole octets. */
96 for (b = bits / 8; b > 0; b--) {
97 if (ep - dst < sizeof "255.")
98 goto emsgsize;
99 advance = snprintf(dst, ep - dst, "%u", *src++);
100 if (advance <= 0 || advance >= ep - dst)
101 goto emsgsize;
102 dst += advance;
103 if (b > 1) {
104 if (dst + 1 >= ep)
105 goto emsgsize;
106 *dst++ = '.';
107 *dst = '\0';
108 }
109 }
110
111 /* Format partial octet. */
112 b = bits % 8;
113 if (b > 0) {
114 if (ep - dst < sizeof ".255")
115 goto emsgsize;
116 if (dst != odst)
117 *dst++ = '.';
118 m = ((1 << b) - 1) << (8 - b);
119 advance = snprintf(dst, ep - dst, "%u", *src & m);
120 if (advance <= 0 || advance >= ep - dst)
121 goto emsgsize;
122 dst += advance;
123 }
124
125 /* Format CIDR /width. */
126 if (ep - dst < sizeof "/32")
127 goto emsgsize;
128 advance = snprintf(dst, ep - dst, "/%u", bits);
129 if (advance <= 0 || advance >= ep - dst)
130 goto emsgsize;
131 dst += advance;
Value stored to 'dst' is never read
132 return (odst);
133
134 emsgsize:
135 errno(*__errno()) = EMSGSIZE40;
136 return (NULL((void *)0));
137}
138
139static char *
140inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
141{
142 int ret;
143 char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")];
144
145 if (bits < 0 || bits > 128) {
146 errno(*__errno()) = EINVAL22;
147 return (NULL((void *)0));
148 }
149
150 if (inet_ntop(AF_INET624, src, buf, size) == NULL((void *)0))
151 return (NULL((void *)0));
152
153 ret = snprintf(dst, size, "%s/%d", buf, bits);
154 if (ret < 0 || ret >= size) {
155 errno(*__errno()) = EMSGSIZE40;
156 return (NULL((void *)0));
157 }
158
159 return (dst);
160}