Skip to content

fix(radio): lua telemetry handling - #7773

Open
3djc wants to merge 2 commits into
mainfrom
3djc/lua-telem-main
Open

fix(radio): lua telemetry handling#7773
3djc wants to merge 2 commits into
mainfrom
3djc/lua-telem-main

Conversation

@3djc

@3djc 3djc commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Reports of radios rebooting into EMERGENCY MODE while using the Rotorflight Lua scripts, and attemps to address it, at least partially.

  1. The Lua telemetry queues have no locking

Telemetry RX runs in the FreeRTOS timer task (prio 2, via xTimerPendFunctionCallFromISR); Lua runs in the menus task (prio 1). So RX preempts Lua at any instruction, and:

  • telemetryQueues is mutated from the menus task while pushTelemetryDataToQueues() iterates it from the timer task, unlocked.
  • ~LuaScriptManager unregisters its queue and then frees it as two separate steps — the producer can still hold that pointer.

Colorlcd only. It fires on script/widget open and close with telemetry streaming.

Fixed with a mutex over the list, held across the whole push loop, and unregister+free collapsed into a single destroyTelemetryQueue() under that lock.

  1. crossfireTelemetryPush() bounds-checks the wrong value

lua_gettop(L) > TELEMETRY_OUTPUT_BUFFER_SIZE compares the argument count (always 2), not the payload length, leaving the payload unbounded. pushByte() drops silently past 64 bytes, but the frame's length byte and crc8(data + 2, ...) still use the full length and read past the buffer. Now checks the real frame size, keeping the length as lua_Integer until validated so a >255 table can't wrap through uint8_t.

The payload loop also lua_rawgeti'd each element without popping it, growing the Lua stack one slot per byte — past LUA_MINSTACK that writes beyond the reserved C-call slots. Added the missing lua_pop().

Untested (as in I wasn't able to reproduce the EM without that fix, so could not confirm this fixes it)

(cherry picked from commit c6df336ca7ecf4bd9ff2928f02e4e53577e6e301)
@philmoz

philmoz commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Are the same fixes needed for ghostTelemetryPush?

@3djc

3djc commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Are the same fixes needed for ghostTelemetryPush?

Technicaly no, because Ghost caps payload at 10 bytes, so bellow LUA_MINSTACK (set at 20)

But yes, it would look nicer and more consistent to have it there too, incoming

Mirror the crossfireTelemetryPush fixes
@3djc 3djc added bug 🪲 Something isn't working lua-application Stuff that should be implemented using Lua backport/2.12 To be backported to a 2.12 release also. labels Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.12 To be backported to a 2.12 release also. bug 🪲 Something isn't working lua-application Stuff that should be implemented using Lua

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants