From f0f536dab34b7023e94f70e9ff7d4c5db1cb9e76 Mon Sep 17 00:00:00 2001 From: whd <7058128+superwhd@users.noreply.github.com> Date: Tue, 1 Jun 2021 12:47:12 +0800 Subject: [PATCH] [udp] fix potential infinite loop in `Udp::GetEphemeralPort` (#6697) The current implementation will go into an infinite loop when mEphemeralPort == Tmf::kUdpPort, since rval is never updated in the loop. This commit fixes this issue. --- src/core/net/udp6.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index b16f4bd46..74bebd4b2 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -407,8 +407,6 @@ exit: uint16_t Udp::GetEphemeralPort(void) { - uint16_t rval = mEphemeralPort; - do { if (mEphemeralPort < kDynamicPortMax) @@ -419,9 +417,9 @@ uint16_t Udp::GetEphemeralPort(void) { mEphemeralPort = kDynamicPortMin; } - } while (rval == Tmf::kUdpPort); + } while (mEphemeralPort == Tmf::kUdpPort); - return rval; + return mEphemeralPort; } Message *Udp::NewMessage(uint16_t aReserved, const Message::Settings &aSettings)