Skip to content

Commit

Permalink
udp realtime - improve robustness against short packets (fix for Airc…
Browse files Browse the repository at this point in the history
…oookie#3672)

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 authored and DedeHai committed Jan 27, 2024
1 parent daa4d13 commit 0015983
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 0015983

Please sign in to comment.