Conversation
|
@esphbot review |
|
Reviewed. Three fixes verified against source. GOT_IP enum equals 7. Old copy truncated Two blockers remain in the new guard. Both are one-line fixes. Details inline. |
|
|
esphbot
left a comment
There was a problem hiding this comment.
Warning
Important issues found.
- Signed guard weakened: negative buf_len now passes the length check
- When the copy is skipped, buf_len is still forwarded — NULL data with a non-zero length
|
Sorry, wrong window, didn't mean to drop a review from the bot on this one. |
|
Both blockers plus the three non-blocking notes, in e3326f7:
Hardware state: an RTL8720DN (BW16) is running this exact code — boots, associates, DHCP, and serves the ESPHome native API with no heap corruption across repeated reconnects. clang-format 19 clean. |
Important Items 1, 3, 4, 5 confirmed fixed. Ownership model now correct both directions. Item 2 overshoots. On Gate on flags: |
|
|
esphbot
left a comment
There was a problem hiding this comment.
Warning
Important issues found.
- Zeroing buf_len destroys the Arduino event id on the flags == -2 path
|
All three, in 18eb65d:
Branch is 0 behind master. Compiled for the AmebaD family (shared file); the previous head runs on BW16 hardware — this delta changes only which id the four no-payload events carry. |
Verified all three against the tree.
One nit: PR body bullet #1 still describes the reverted design — "task skips the free for Arduino events, leaving ownership with |
|
|
esphbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
Note No code changes since the last review ( |
|
Hardware confirmation of the final revision on RTL8720DN: with event-flow instrumentation in the queue path, a no-payload Arduino event now arrives as — STA_START (2) delivered with its id intact through the NULL-buf path, the exact case the last review round fixed. Association, DHCP and the ESPHome native API all run on this code. |
18eb65d to
0a14b62
Compare
|
Both notes addressed: the description's ownership bullet now states the final design (task owns and frees the queued copy for every flags value; handleRtwEvent frees nothing), and 0a14b62 adds a log line on both heap-pressure drop paths in wifi_indication() — the event-record malloc and the payload malloc — so a dropped disconnect under memory pressure is visible in the field. The third path (address below WIFI_EVENT_BUF_MIN_ADDR) stays silent deliberately: that is the documented value-in-buf convention (AmebaD passes buf=0x1 on every no-payload Arduino event), so a log there would fire on routine mode changes, not on losses. |
…t data wifi_indication() copies every queued payload and wifiEventTask() owns and frees that copy for every flags value; handleRtwEvent() frees nothing. The flags == -2 no-payload path keeps the Arduino event id, allocation failures drop the event with a log line instead of queueing a NULL payload, and the DISASSOC MAC copy is guarded against short buffers.
0a14b62 to
d46c3d4
Compare
Both notes confirmed closed. Description bullet now matches implemented ownership model. Log lines cover both heap-pressure drops. Low-address silence accepted per your rationale: One leftover note only: |
PR Review — realtek-amb: fix double free and truncated copy of Arduino WiFi event dataBoth outstanding notes are closed and nothing new blocks merge — approving. The ownership model is now stated identically in three places that used to disagree: the PR body, the inline comment at The sanitization logic holds across all four combinations I traced: valid pointer +
✅ Resolved since last review (1)Previously-flagged issues verified fixed
🟢 Suggestions
1. `flags == -2` now carries an implicit "buffer is at least sizeof(EventInfo)" contract with nothing enforcing it
|
esphbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
Summary
Three defects in the Arduino WiFi event path shared by all
realtek-ambfamilies (AmebaZ, AmebaZ2, and the AmebaD work in progress). Found while bringing up RTL8720DN: the device hard-faulted insidememcpycalled fromwifi_indication(), with0xdeadbeefin R0-R3 (heap poison).1. Double free of the event buffer
WiFiSTA.cpp:157queues a realEventInfo *withflags == -2:wifi_indication()copies it intoev->buf. ThenhandleRtwEvent()frees that copy in theflags == -2branch, andwifiEventTask()frees the same pointer again immediately afterwards.wifiEventTask()now owns and frees the queued copy for everyflagsvalue;handleRtwEvent()frees nothing — one deletion retires the double free on both the queued and the non-queued path.2. Copy length taken from an event id
On the
flags == -2pathbuf_lencarries the Arduino event id, not a byte count, so theEventInfowas copied at whatever length that id happened to be. It now copiessizeof(EventInfo).3. Null event info dereferenced
Events raised with no payload (
ARDUINO_EVENT_WIFI_STA_STARTand friends inWiFiGeneric.cpp/WiFiAP.cpp) passbuf == NULL, which reached*eventInfo. Now handled explicitly.The copy is also guarded against a
bufthat is not a pointer: the AmebaD driver callswifi_indication()withbuf = 0x1, buf_len = 2while switching modes, which is what produced the original fault.Testing
bw15(AmebaZ2) with this change: SUCCESS, RAM 4.8%, flash 38.5%.GOT_IPwithout heap corruption.