Repository navigation
Conversation
…fore using them Nothing checked how many bytes a frame had before its command or event read them. A short or damaged frame was run from the stale rest of its buffer: CMD_SET_BAUD set a baud rate, flow control and line polarity from nothing (and then slept a second), CMD_WIFI_CONNECT a Wi-Fi SSID and password, CMD_SEND_PACKET put as many bytes on the air as a stale length said. On the Ultimate's side a module that answers such a command "not implemented" echoes the command byte, which can be an event code: an EVENT_CONNECTED of 8 bytes made the task take an SSID from the buffer's earlier life (seen on a C64 Ultimate: "Could not connect to <garbage>"). Modules (raw_u64, raw_c3, u64ctrl): rpc_request_too_short() in rpc_dispatch.c, before the dispatch: nothing below a header; the whole request structure of CMD_SET_BAUD, CMD_GET_TIME and, on u64ctrl, CMD_SET_SERIAL, CMD_SET_POWER_MODE, CMD_SET_WAKE_ON_WIFI, CMD_SET_RECOVERY_URL (the Ultimate sends the whole structure of each); 98 bytes for CMD_WIFI_CONNECT as cmd_wifi_connect has it; for CMD_SEND_PACKET the 8-byte head and the length it claims. A short request with a header is answered ESP_ERR_INVALID_ARG, one without is dropped; both are counted and logged. Every other command reads its header only. Ultimate (wifi.cc, wifi_event_size.h): wifi_event_too_short() before the event switch: nothing below a header; EVENT_CONNECTED its 32-byte SSID, EVENT_GOTIP the address, EVENT_RECV_PACKET its length and that many bytes. Only what the task reads, so an older module with shorter events still works. The two internal events (sendEvent, sendConnectEvent) now set their size. Host tests (software/wifi/tests/rpc, `make test`, `make red`): every command below a header, the request structures one byte short and whole, the packet length, each event; RED against the code without a check (1031 failing checks per module), 14 models of a missing or wrong check, all killed. The module identity is bumped as a placeholder; the maintainers assign the number at merge. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
GideonZ#1041 (wifi-fixes) adds its own software/wifi/tests; the trees must not share a directory. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The handler prints the address and the flag after the gateway; the check stopped at the address. The modules send the event whole (sizeof(event_pkt_got_ip)), so nothing real is rejected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ptional BSSID Re-places the Ultimate-side check inside GideonZ#1041's RunModeThread and extends it to what GideonZ#1041 adds: EVENT_CONNECT_PENDING (the SSID of the attempt, read by feedback.begin(); the internal sender now sets the size), EVENT_RADIO_SETTING / EVENT_CONNECT_ANSWER / EVENT_RESTARTED (a header is all they read), EVENT_DISCONNECTED (its reason is read through wifi_disconnect_reason(), which asks for the size itself, so a bare header is let through). The connect request's check is now the one cmd_wifi_connect makes (the password whole; the BSSID and channel after it are optional). The module identity is bumped as a placeholder; the maintainers assign the number at merge. Runs in make host_tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ed for, as compile-time assertions Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ize the module sends them software/io/wifi/tests compiles RunModeThread, which now calls wifi_event_too_short() and counts in wifi_events_short: the harness includes the header and declares the counter, and its scripted EVENT_CONNECTED / EVENT_CONNECT_PENDING / EVENT_GOTIP are the whole structures, as the module and sendConnectPending send them (a header-only one was never real). The drop message prints the command in decimal: the firmware printf has no %b argument. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Clean merge, no conflicts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Master is merged into this branch now that #1041 is in (e9ec844), so the diff here is only the size checks. The branch is updated by a merge, not a rebase, following your note on #1041 that base updates go in by merge. #1042 was the only other PR carrying #1041's commits; it has the same update (9d24bbb), with the old sed models deleted as on master. The host tests of both pass. Written with Claude Sonnet and Claude Opus in Claude Code. |
…deonZ#1080) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Yes, it's ready. #1041 was the only thing it waited for. It's now up to date with master and CI is green, and I've updated the description so it no longer refers to #1041 as pending. The hardware runs in the description used a bench build from before this merge; the merge brings in master only. One note: its module version numbers will need renumbering if #1042 or the UART PRs (#1077-#1079) merge first. Written with Claude Opus and Claude Sonnet in Claude Code. |
|
Thanks. I read the check in wifi_event_size.h and the module side in raw_u64; the minimum sizes match what the handlers read, and the old-module case (shorter events) is covered. Nothing to change in the code. Two things before it can merge. The module versions need renumbering depending on the order of #1042 and #1077 to #1079, so please agree an order. The cartridge targets are CI-built only; fine to state, but then this should go in after the Elite and C64 Ultimate runs are repeated on the final merge result. |
|
Proposed merge order: #1077, #1078, #1079, #1080, then #1042. #1077 only adds tests and has no module version. #1078 contains #1077's tests and #1079 contains #1078's change, so they go in that order. #1080 follows, and I'll repeat the Elite and C64 Ultimate runs on the merge result before it goes in. #1042 goes last, as you asked on that PR. As each PR lands, I'll merge master into the next one and bump its module minor version past the one before. No rebases. Written with Claude Opus and Claude Sonnet in Claude Code. |
|
Thanks, much appreciated. TRX64 is Jondalar's work though, not mine. The credit for that one goes to him. |
Fixes #1075
Problem
Nothing checked how many bytes a frame had before its command or event read them. A short or damaged frame was run from the stale rest of its buffer: CMD_SET_BAUD set a baud rate, flow control and line polarity from nothing (and then slept a second), CMD_WIFI_CONNECT used a Wi-Fi SSID and password, CMD_SEND_PACKET put as many bytes on the air as a stale length said. On the Ultimate's side a module that answers such a command "not implemented" echoes the command byte, which can be an event code: an 8-byte EVENT_CONNECTED made the task take an SSID from the buffer's earlier life ("Could not connect to " on a C64 Ultimate). #1041 added new payload readers (the SSID of a connect attempt, the optional BSSID, the radio setting events) that read their bytes unchecked in the same way.
What changed and why
Modules: a check before the dispatch. Nothing below a header; the whole request structure of CMD_SET_BAUD, CMD_GET_TIME (and on u64ctrl CMD_SET_SERIAL, CMD_SET_POWER_MODE, CMD_SET_WAKE_ON_WIFI, CMD_SET_RECOVERY_URL); 98 bytes for CMD_WIFI_CONNECT; for CMD_SEND_PACKET the 8-byte head and the length it claims. A short request with a header is answered ESP_ERR_INVALID_ARG, one without is dropped; both are counted and logged. Ultimate side: a check before the event switch inside #1041's
RunModeThread, only for what the task reads, so an older module with shorter events still works. It covers what #1041 added: EVENT_CONNECT_PENDING (the SSID of the attempt), EVENT_RADIO_SETTING / EVENT_CONNECT_ANSWER / EVENT_RESTARTED (a header is all they read), EVENT_DISCONNECTED (its reason is read through a function that asks for the size itself). The connect request's check is the onecmd_wifi_connectmakes (the password whole; BSSID and channel after it are optional). Compile-time assertions tie the senders' sizes to the sizes asked for, and the host task harness sends events at the size the module sends them.Needs #1041, which is merged.
Products. the ESP32 modules (raw_u64, raw_c3, u64ctrl) and the Ultimate-side WiFi task, so every product with the WiFi module: the Ultimate 64, Ultimate 64 Elite II, C64 Ultimate and the Ultimate-II cartridges (U2+, U2+L). Host tests, and on hardware on both devices (see below).
How I tested it
Host: macOS, with the device-free tests run in an Ubuntu 24.04 container (g++ 13.3). The hardware runs used the test harness from the same machine.
Host tests (device-free, run before and after the change):
make -C software/wifi/size_tests test; make -C software/wifi/size_tests red; make host_testsmake host_testsbuilds the size-check tests and then stops atrecoverymanifest(mbedTLS/ESP-IDF, absent in the container), which is unrelatedHardware.
On hardware, this build was flashed on both the U64 Elite and the C64 Ultimate and driven by a bench-only test build that sends deliberately short messages. Undersized module requests — a time request, a send-packet request claiming more bytes than it carries, and a baud-rate request — are refused by the module with an error reply, and the module answers the next normal request straight away. Undersized events toward the Ultimate — including the connect events this variant adds, read inside #1041's
RunModeThread— are logged and dropped, with nothing acting on them (no connection or address is reported from a short event). Across real Wi-Fi connect/disconnect cycles, the network suites and the soaks, no legitimate message was rejected.Standard profile: the flash round ran the network suites and the soaks (above), not the full standard profile. The host-driven
./run-testsstandard profile does not exercise the module-side firmware in any case.Untested
Written with Claude Opus 5.5 in Claude Code.