Skip to content

Commit 151cf32

Browse files
authored
[tcp][posix] ensure struct fields are initialized (openthread#11552)
This aims to fix some instances in core/tcp6 and posix/udp where the complete struct was not initialized. In otPlatUdpJoinMulticastGroup and otPlatUdpLeaveMulticastGroup an explicit redundant setting to '0' is added just for clarity for people reading the code.
1 parent 5050bec commit 151cf32

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/core/net/tcp6.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Error Tcp::Endpoint::Connect(const SockAddr &aSockName, uint32_t aFlags)
163163
struct sockaddr_in6 sin6p;
164164

165165
tp.t_flags &= ~TF_FASTOPEN;
166+
ClearAllBytes(sin6p);
166167
memcpy(&sin6p.sin6_addr, &aSockName.mAddress, sizeof(sin6p.sin6_addr));
167168
sin6p.sin6_port = BigEndian::HostSwap16(aSockName.mPort);
168169
error = BsdErrorToOtError(tcp6_usr_connect(&tp, &sin6p));
@@ -193,6 +194,7 @@ Error Tcp::Endpoint::SendByReference(otLinkedBuffer &aBuffer, uint32_t aFlags)
193194

194195
if (IS_FASTOPEN(tp.t_flags))
195196
{
197+
ClearAllBytes(sin6p);
196198
memcpy(&sin6p.sin6_addr, &tp.faddr, sizeof(sin6p.sin6_addr));
197199
sin6p.sin6_port = tp.fport;
198200
name = &sin6p;
@@ -221,6 +223,7 @@ Error Tcp::Endpoint::SendByExtension(size_t aNumBytes, uint32_t aFlags)
221223

222224
if (IS_FASTOPEN(tp.t_flags))
223225
{
226+
ClearAllBytes(sin6p);
224227
memcpy(&sin6p.sin6_addr, &tp.faddr, sizeof(sin6p.sin6_addr));
225228
sin6p.sin6_port = tp.fport;
226229
name = &sin6p;

src/posix/platform/udp.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ otError otPlatUdpJoinMulticastGroup(otUdpSocket *aUdpSocket,
463463
const otIp6Address *aAddress)
464464
{
465465
otError error = OT_ERROR_NONE;
466-
struct ipv6_mreq mreq;
466+
struct ipv6_mreq mreq = {};
467467
int fd;
468468

469469
VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS);
@@ -474,6 +474,7 @@ otError otPlatUdpJoinMulticastGroup(otUdpSocket *aUdpSocket,
474474
switch (aNetifIdentifier)
475475
{
476476
case OT_NETIF_UNSPECIFIED:
477+
mreq.ipv6mr_interface = 0; // Explicitly set to 0 to clarify intention.
477478
break;
478479
case OT_NETIF_THREAD_HOST:
479480
mreq.ipv6mr_interface = gNetifIndex;
@@ -506,7 +507,7 @@ otError otPlatUdpLeaveMulticastGroup(otUdpSocket *aUdpSocket,
506507
const otIp6Address *aAddress)
507508
{
508509
otError error = OT_ERROR_NONE;
509-
struct ipv6_mreq mreq;
510+
struct ipv6_mreq mreq = {};
510511
int fd;
511512

512513
VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS);
@@ -517,6 +518,7 @@ otError otPlatUdpLeaveMulticastGroup(otUdpSocket *aUdpSocket,
517518
switch (aNetifIdentifier)
518519
{
519520
case OT_NETIF_UNSPECIFIED:
521+
mreq.ipv6mr_interface = 0; // Explicitly set to 0 to clarify intention.
520522
break;
521523
case OT_NETIF_THREAD_HOST:
522524
mreq.ipv6mr_interface = gNetifIndex;

0 commit comments

Comments
 (0)