Repository navigation
fix(net,rmt_rx): heap-ownership handshake + ISR copy underflow guard (#3588) - #3599
Merged
Merged
Conversation
…R copy underflow guard (#3588) Two genuine memory-safety defects found while investigating #3588. Neither fully cures the WROOM corruption (it still reproduces — see the issue), but both are real out-of-bounds/UAF bugs worth fixing on their own merits. 1. esp_http_server marshaling (server.cpp.hpp): the request item that the httpd task hands to the main-loop runner was STACK-allocated. When the 5 s handler wait timed out, handle_esp_request returned and its stack frame died while the item pointer was still live in the queue — the runner then wrote *response through freed stack memory. The item is now heap-allocated with an atomic ownership handshake (CAS state 0→1 runner-claims / 0→3 httpd-abandons) that deterministically assigns cleanup to exactly one side, with no double-free and no dangling pointer on either the timeout or the normal path. Also fixes a NUL-terminator bug from the prior patch: four `str[i] = '\0'` writes had been stored as literal NUL *bytes* in the source char literals (functionally correct but tool-hostile) — now proper `'\0'` escapes. 2. RMT-RX accumulation copy (rmt_rx_channel_5.cpp.hpp): the `available_space = buffer.size() - offset` computation UNDERFLOWS to a huge value if a late callback lands while the buffer is cleared (size 0) but the offset is still stale-nonzero, causing the symbol copy to write far past the buffer. Guarded with an explicit `offset < size` check. Verified on WROOM: I2S/RMT/UART/SPI loopback all 4/4, dual-device marshaled HTTP serves over the air. Host 349/349, lint clean, esp32dev/c6/s3 compile clean. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR hardens ESP32 HTTP server request lifecycle management by adding atomic state tracking and centralized cleanup to prevent stale pointer access and heap corruption, and adds a bounds check in the RMT RX ISR callback to prevent buffer size underflow. ChangesESP32 HTTP Server Request Lifecycle
RMT RX ISR Underflow Guard
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Jul 5, 2026
This was referenced Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two genuine memory-safety defects found while investigating #3588. Neither fully cures the WROOM corruption (it still reproduces — see issue), but both are real OOB/UAF bugs.
1. Marshaling request-item lifetime (
server.cpp.hpp)The request item the httpd task handed to the main-loop runner was stack-allocated. On a 5 s handler-wait timeout,
handle_esp_requestreturned and its stack frame died while the item pointer was still live in the queue — the runner then wrote*responsethrough freed stack memory. Now heap-allocated with an atomic ownership handshake (CAS0→1runner-claims /0→3httpd-abandons) that assigns cleanup to exactly one side. No double-free, no dangling pointer on either the timeout or normal path.Also fixes a NUL-terminator bug from the prior patch: four
str[i] = '\0'writes were stored as literal NUL bytes in the source char literals — now proper'\0'escapes.2. RMT-RX accumulation copy underflow (
rmt_rx_channel_5.cpp.hpp)available_space = buffer.size() - offsetunderflows to a huge value if a late callback lands while the buffer is cleared (size 0) with a stale-nonzero offset, letting the symbol copy write past the buffer. Guarded with an explicitoffset < sizecheck.Validation
WROOM I2S/RMT/UART/SPI loopback 4/4; dual-device marshaled HTTP serves over the air. Host 349/349, lint clean, esp32dev/c6/s3 compile clean.
Refs #3588.
🤖 Generated with Claude Code
Summary by CodeRabbit