Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/netwerk/base/NetworkInfoServiceLinux.cpp
Warning:line 74, column 11
Although the value stored to 'family' is used in the enclosing expression, the value is never actually read from 'family'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name NetworkInfoServiceLinux.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -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 -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -relaxed-aliasing -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -D DEBUG=1 -D OS_POSIX=1 -D OS_LINUX=1 -D STATIC_EXPORTABLE_JS_API -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/base -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/netwerk/base -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/glue -I /var/lib/jenkins/workspace/firefox-scan-build/docshell/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/base -I /var/lib/jenkins/workspace/firefox-scan-build/extensions/permissions -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/protocol/http -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/socket -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/url-classifier -I /var/lib/jenkins/workspace/firefox-scan-build/security/manager/ssl -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -Wwrite-strings -Wno-invalid-offsetof -Wno-error=maybe-uninitialized -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=coverage-mismatch -Wno-error=free-nonheap-object -Wno-error=shadow -fdeprecated-macro -fdebug-compilation-dir /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/netwerk/base -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fno-rtti -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-checker optin.cplusplus.UninitializedObject -analyzer-checker alpha.cplusplus.IteratorRange -analyzer-checker alpha.core.BoolAssignment -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2019-10-10-015354-10307-1 -x c++ /var/lib/jenkins/workspace/firefox-scan-build/netwerk/base/NetworkInfoServiceLinux.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include <string.h>
8#include <unistd.h>
9#include <sys/ioctl.h>
10#include <sys/socket.h>
11#include <sys/types.h>
12#include <net/if.h>
13#include <netdb.h>
14
15#include "mozilla/DebugOnly.h"
16#include "mozilla/ScopeExit.h"
17
18#include "NetworkInfoServiceImpl.h"
19
20namespace mozilla {
21namespace net {
22
23static nsresult ListInterfaceAddresses(int aFd, const char* aIface,
24 AddrMapType& aAddrMap);
25
26nsresult DoListAddresses(AddrMapType& aAddrMap) {
27 int fd = socket(AF_INET2, SOCK_DGRAMSOCK_DGRAM, 0);
28 if (fd < 0) {
29 return NS_ERROR_FAILURE;
30 }
31
32 auto autoCloseSocket = MakeScopeExit([&] { close(fd); });
33
34 struct ifconf ifconf;
35 /* 16k of space should be enough to list all interfaces. Worst case, if it's
36 * not then we will error out and fail to list addresses. This should only
37 * happen on pathological machines with way too many interfaces.
38 */
39 char buf[16384];
40
41 ifconf.ifc_len = sizeof(buf);
42 ifconf.ifc_bufifc_ifcu.ifcu_buf = buf;
43 if (ioctl(fd, SIOCGIFCONF0x8912, &ifconf) != 0) {
44 return NS_ERROR_FAILURE;
45 }
46
47 struct ifreq* ifreq = ifconf.ifc_reqifc_ifcu.ifcu_req;
48 int i = 0;
49 while (i < ifconf.ifc_len) {
50 size_t len = sizeof(struct ifreq);
51
52 DebugOnly<nsresult> rv =
53 ListInterfaceAddresses(fd, ifreq->ifr_nameifr_ifrn.ifrn_name, aAddrMap);
54 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "ListInterfaceAddresses failed")do { if (!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1
))))) { NS_DebugBreak(NS_DEBUG_WARNING, "ListInterfaceAddresses failed"
, "NS_SUCCEEDED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/netwerk/base/NetworkInfoServiceLinux.cpp"
, 54); } } while (false)
;
55
56 ifreq = (struct ifreq*)((char*)ifreq + len);
57 i += len;
58 }
59
60 return NS_OK;
61}
62
63static nsresult ListInterfaceAddresses(int aFd, const char* aInterface,
64 AddrMapType& aAddrMap) {
65 struct ifreq ifreq;
66 memset(&ifreq, 0, sizeof(struct ifreq));
67 strncpy(ifreq.ifr_nameifr_ifrn.ifrn_name, aInterface, IFNAMSIZ16 - 1);
68 if (ioctl(aFd, SIOCGIFADDR0x8915, &ifreq) != 0) {
69 return NS_ERROR_FAILURE;
70 }
71
72 char host[128];
73 int family;
74 switch (family = ifreq.ifr_addrifr_ifru.ifru_addr.sa_family) {
Although the value stored to 'family' is used in the enclosing expression, the value is never actually read from 'family'
75 case AF_INET2:
76 case AF_INET610:
77 getnameinfo(&ifreq.ifr_addrifr_ifru.ifru_addr, sizeof(ifreq.ifr_addrifr_ifru.ifru_addr), host, sizeof(host),
78 nullptr, 0, NI_NUMERICHOST1);
79 break;
80 case AF_UNSPEC0:
81 return NS_OK;
82 default:
83 // Unknown family.
84 return NS_OK;
85 }
86
87 nsCString ifaceStr;
88 ifaceStr.AssignASCII(aInterface);
89
90 nsCString addrStr;
91 addrStr.AssignASCII(host);
92
93 aAddrMap.Put(ifaceStr, addrStr);
94
95 return NS_OK;
96}
97
98} // namespace net
99} // namespace mozilla