Skip to content

Commit

Permalink
Fix buffering of user payloads (#243)
Browse files Browse the repository at this point in the history
Issue identified by @mirhamza708

* Fix buffering of user payloads: Per #242 fix buffer overrun
* Mods to #243 per @2bndy5
  • Loading branch information
TMRh20 authored and 2bndy5 committed Jan 10, 2025
1 parent 11c367b commit de66f95
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,16 @@ uint8_t RF24Network::enqueue(RF24NetworkHeader* header)
return 0;
}
#else // !defined(DISABLE_USER_PAYLOADS)
if (message_size + (next_frame - frame_queue) <= MAIN_BUFFER_SIZE) {
#if !defined(ARDUINO_ARCH_AVR)
uint8_t padding = (message_size + 10) % 4;
padding = padding ? 4 - padding : 0;
if (padding +
#else
if (
#endif
message_size + 10 + (next_frame - frame_queue)
<= MAIN_BUFFER_SIZE)
{
memcpy(next_frame, &frame_buffer, 8);
memcpy(next_frame + 8, &message_size, 2);
memcpy(next_frame + 10, frame_buffer + 8, message_size);
Expand All @@ -514,9 +523,7 @@ uint8_t RF24Network::enqueue(RF24NetworkHeader* header)

next_frame += (message_size + 10);
#if !defined(ARDUINO_ARCH_AVR)
if (uint8_t padding = (message_size + 10) % 4) {
next_frame += 4 - padding;
}
next_frame += padding;
#endif
//IF_RF24NETWORK_DEBUG_FRAGMENTATION( Serial.print("Enq "); Serial.println(next_frame-frame_queue); );//printf_P(PSTR("enq %d\n"),next_frame-frame_queue); );

Expand Down

0 comments on commit de66f95

Please sign in to comment.