Skip to content

Commit 1943fc2

Browse files
andy31415andreilitvinrestyled-commits
authored andcommitted
Additional socket checks for socket inet implementations (project-chip#35674)
* Additional socket checks for socket inet implementations * Self-review update * One more extra check to make clang-tidy happy * Switch to nolint * Avoid large code deltas * Restyle * Restyled by clang-format --------- Co-authored-by: Andrei Litvin <[email protected]> Co-authored-by: Restyled.io <[email protected]>
1 parent 751acd3 commit 1943fc2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/inet/TCPEndPointImplSockets.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ CHIP_ERROR TCPEndPointImplSockets::BindImpl(IPAddressType addrType, const IPAddr
127127

128128
if (res == CHIP_NO_ERROR)
129129
{
130+
// NOLINTNEXTLINE(clang-analyzer-unix.StdCLibraryFunctions): GetSocket calls ensure mSocket is valid
130131
if (bind(mSocket, &sa.any, sockaddrsize) != 0)
131132
{
132133
res = CHIP_ERROR_POSIX(errno);
@@ -248,6 +249,7 @@ CHIP_ERROR TCPEndPointImplSockets::ConnectImpl(const IPAddress & addr, uint16_t
248249
return INET_ERROR_WRONG_ADDRESS_TYPE;
249250
}
250251

252+
// NOLINTNEXTLINE(clang-analyzer-unix.StdCLibraryFunctions): GetSocket calls ensure mSocket is valid
251253
int conRes = connect(mSocket, &sa.any, sockaddrsize);
252254

253255
if (conRes == -1 && errno != EINPROGRESS)

src/inet/UDPEndPointImplSockets.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ CHIP_ERROR IPv6Bind(int socket, const IPAddress & address, uint16_t port, Interf
106106
sa.sin6_scope_id = static_cast<decltype(sa.sin6_scope_id)>(interfaceId);
107107

108108
CHIP_ERROR status = CHIP_NO_ERROR;
109+
110+
// NOLINTNEXTLINE(clang-analyzer-unix.StdCLibraryFunctions): Function called only with valid socket after GetSocket
109111
if (bind(socket, reinterpret_cast<const sockaddr *>(&sa), static_cast<unsigned>(sizeof(sa))) != 0)
110112
{
111113
status = CHIP_ERROR_POSIX(errno);
@@ -139,6 +141,8 @@ CHIP_ERROR IPv4Bind(int socket, const IPAddress & address, uint16_t port)
139141
sa.sin_addr = address.ToIPv4();
140142

141143
CHIP_ERROR status = CHIP_NO_ERROR;
144+
145+
// NOLINTNEXTLINE(clang-analyzer-unix.StdCLibraryFunctions): Function called only with valid socket after GetSocket
142146
if (bind(socket, reinterpret_cast<const sockaddr *>(&sa), static_cast<unsigned>(sizeof(sa))) != 0)
143147
{
144148
status = CHIP_ERROR_POSIX(errno);
@@ -410,6 +414,7 @@ CHIP_ERROR UDPEndPointImplSockets::SendMsgImpl(const IPPacketInfo * aPktInfo, Sy
410414
#endif // INET_CONFIG_UDP_SOCKET_PKTINFO
411415

412416
// Send IP packet.
417+
// NOLINTNEXTLINE(clang-analyzer-unix.StdCLibraryFunctions): GetSocket calls ensure mSocket is valid
413418
const ssize_t lenSent = sendmsg(mSocket, &msgHeader, 0);
414419
if (lenSent == -1)
415420
{

0 commit comments

Comments
 (0)