mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
e3d03f4f14
This commit fixes a logic error in the TCP receive buffer reassembly logic. The issue occurred when an out-of-order segment was exactly the size of the circular buffer and the write index was non-zero. The original logic incorrectly used modulo-wrapped indices to check if a write should be contiguous or split: start_index + numbytes % size. When numbytes == size, end_index == start_index, which evaluates to true, leading to an incorrect memory write if start_index > 0. This commit updates the check to use the absolute write boundary: if (start_index + numbytes <= chdr->size). This ensures that any write spanning the buffer boundary is correctly split. A regression test test_cbuf_reass_boundary is added to test_all.c to verify the fix and prevent future regressions. The test Makefile is also updated to use $(CC) for better portability.