Bug Summary

File:src/gnu/usr.bin/clang/liblldbHostCommon/../../../llvm/lldb/source/Host/common/UDPSocket.cpp
Warning:line 130, column 3
Value stored to 'err' 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 UDPSocket.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 -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/liblldbHostCommon/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/liblldbHostCommon/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/liblldbHostCommon/../include -I /usr/src/gnu/usr.bin/clang/liblldbHostCommon/obj -I /usr/src/gnu/usr.bin/clang/liblldbHostCommon/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -I /usr/src/gnu/usr.bin/clang/liblldbHostCommon/../../../llvm/lldb/include -I /usr/src/gnu/usr.bin/clang/liblldbHostCommon/../../../llvm/lldb/source -I /usr/src/gnu/usr.bin/clang/liblldbHostCommon/../../../llvm/clang/include -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/liblldbHostCommon/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -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/gnu/usr.bin/clang/liblldbHostCommon/../../../llvm/lldb/source/Host/common/UDPSocket.cpp
1//===-- UDPSocket.cpp -----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Host/common/UDPSocket.h"
10
11#include "lldb/Host/Config.h"
12#include "lldb/Utility/Log.h"
13
14#if LLDB_ENABLE_POSIX1
15#include <arpa/inet.h>
16#include <sys/socket.h>
17#endif
18
19#include <memory>
20
21using namespace lldb;
22using namespace lldb_private;
23
24namespace {
25
26const int kDomain = AF_INET2;
27const int kType = SOCK_DGRAM2;
28
29static const char *g_not_supported_error = "Not supported";
30}
31
32UDPSocket::UDPSocket(NativeSocket socket) : Socket(ProtocolUdp, true, true) {
33 m_socket = socket;
34}
35
36UDPSocket::UDPSocket(bool should_close, bool child_processes_inherit)
37 : Socket(ProtocolUdp, should_close, child_processes_inherit) {}
38
39size_t UDPSocket::Send(const void *buf, const size_t num_bytes) {
40 return ::sendto(m_socket, static_cast<const char *>(buf), num_bytes, 0,
41 m_sockaddr, m_sockaddr.GetLength());
42}
43
44Status UDPSocket::Connect(llvm::StringRef name) {
45 return Status("%s", g_not_supported_error);
46}
47
48Status UDPSocket::Listen(llvm::StringRef name, int backlog) {
49 return Status("%s", g_not_supported_error);
50}
51
52Status UDPSocket::Accept(Socket *&socket) {
53 return Status("%s", g_not_supported_error);
54}
55
56llvm::Expected<std::unique_ptr<UDPSocket>>
57UDPSocket::Connect(llvm::StringRef name, bool child_processes_inherit) {
58 std::unique_ptr<UDPSocket> socket;
59
60 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION(1u << 13)));
61 LLDB_LOG(log, "host/port = {0}", name)do { ::lldb_private::Log *log_private = (log); if (log_private
) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbHostCommon/../../../llvm/lldb/source/Host/common/UDPSocket.cpp"
, __func__, "host/port = {0}", name); } while (0)
;
62
63 Status error;
64 std::string host_str;
65 std::string port_str;
66 int32_t port = INT32_MIN(-0x7fffffff - 1);
67 if (!DecodeHostAndPort(name, host_str, port_str, port, &error))
68 return error.ToError();
69
70 // At this point we have setup the receive port, now we need to setup the UDP
71 // send socket
72
73 struct addrinfo hints;
74 struct addrinfo *service_info_list = nullptr;
75
76 ::memset(&hints, 0, sizeof(hints));
77 hints.ai_family = kDomain;
78 hints.ai_socktype = kType;
79 int err = ::getaddrinfo(host_str.c_str(), port_str.c_str(), &hints,
80 &service_info_list);
81 if (err != 0) {
82 error.SetErrorStringWithFormat(
83#if defined(_WIN32) && defined(UNICODE)
84 "getaddrinfo(%s, %s, &hints, &info) returned error %i (%S)",
85#else
86 "getaddrinfo(%s, %s, &hints, &info) returned error %i (%s)",
87#endif
88 host_str.c_str(), port_str.c_str(), err, gai_strerror(err));
89 return error.ToError();
90 }
91
92 for (struct addrinfo *service_info_ptr = service_info_list;
93 service_info_ptr != nullptr;
94 service_info_ptr = service_info_ptr->ai_next) {
95 auto send_fd = CreateSocket(
96 service_info_ptr->ai_family, service_info_ptr->ai_socktype,
97 service_info_ptr->ai_protocol, child_processes_inherit, error);
98 if (error.Success()) {
99 socket.reset(new UDPSocket(send_fd));
100 socket->m_sockaddr = service_info_ptr;
101 break;
102 } else
103 continue;
104 }
105
106 ::freeaddrinfo(service_info_list);
107
108 if (!socket)
109 return error.ToError();
110
111 SocketAddress bind_addr;
112
113 // Only bind to the loopback address if we are expecting a connection from
114 // localhost to avoid any firewall issues.
115 const bool bind_addr_success = (host_str == "127.0.0.1" || host_str == "localhost")
116 ? bind_addr.SetToLocalhost(kDomain, port)
117 : bind_addr.SetToAnyAddress(kDomain, port);
118
119 if (!bind_addr_success) {
120 error.SetErrorString("Failed to get hostspec to bind for");
121 return error.ToError();
122 }
123
124 bind_addr.SetPort(0); // Let the source port # be determined dynamically
125
126 err = ::bind(socket->GetNativeSocket(), bind_addr, bind_addr.GetLength());
127
128 struct sockaddr_in source_info;
129 socklen_t address_len = sizeof (struct sockaddr_in);
130 err = ::getsockname(socket->GetNativeSocket(),
Value stored to 'err' is never read
131 (struct sockaddr *)&source_info, &address_len);
132
133 return std::move(socket);
134}
135
136std::string UDPSocket::GetRemoteConnectionURI() const {
137 if (m_socket != kInvalidSocketValue) {
138 return std::string(llvm::formatv(
139 "udp://[{0}]:{1}", m_sockaddr.GetIPAddress(), m_sockaddr.GetPort()));
140 }
141 return "";
142}