Skip to content

Commit

Permalink
udp realtime - improve robustness against short packets (fix for #3672)
Browse files Browse the repository at this point in the history
when only two bytes were received in a packet, the "for" condition `packetsize -3` would underflow, leading to an infinite loop.
  • Loading branch information
softhack007 committed Jan 11, 2024
1 parent a11cab0 commit a9eb7cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions wled00/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void handleNotifications()
if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) return;

uint16_t totalLen = strip.getLengthTotal();
if (udpIn[0] == 1) //warls
if ((udpIn[0] == 1) && (packetSize > 5)) //warls - avoiding infinite "for" loop (unsigned underflow)
{
for (size_t i = 2; i < packetSize -3; i += 4)
{
Expand All @@ -540,7 +540,7 @@ void handleNotifications()

id++; if (id >= totalLen) break;
}
} else if (udpIn[0] == 3) //drgbw
} else if ((udpIn[0] == 3) && (packetSize > 5)) //drgbw - avoiding infinite "for" loop (unsigned underflow)
{
uint16_t id = 0;
for (size_t i = 2; i < packetSize -3; i += 4)
Expand Down

0 comments on commit a9eb7cb

Please sign in to comment.