Skip to content

fix(discord,gateway): inbound WS buffer overflow and WebChat drop - #81

Draft
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/high-severity-issues-ffcf
Draft

fix(discord,gateway): inbound WS buffer overflow and WebChat drop#81
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/high-severity-issues-ffcf

Conversation

@cursor

@cursor cursor Bot commented Sep 7, 2026

Copy link
Copy Markdown

Summary

Two inbound WebSocket buffer bugs: Discord Gateway RX wrote a NUL one byte past the heap block, and dashboard WebChat silently dropped messages larger than one 256-byte LWS callback.

Bug 1 — Discord Gateway RX heap overflow (CRITICAL)

Bug 2 — WebChat inbound frames not reassembled (HIGH)

  • File/function: src/gateway/http.c protocols "ws" .rx_buffer_size = 256; src/gateway/http_lws.c ws_callback LWS_CALLBACK_RECEIVE
  • Trigger: Dashboard WebChat text ≳ ~220 characters ({"type":"message","text":"..."}). LWS splits at 256 bytes; each chunk is cJSON_Parsed as a complete object and fails; the user message is dropped.
  • Impact: Significant user-facing breakage: any non-trivial dashboard message never reaches the agent.
  • Distinct from fix(webchat): align WebSocket payload limit with agent response buffer #62: that PR changes outbound dequeue/frame size, not inbound rx_buffer_size or fragment reassembly.

Fix

  • Grow Discord RX when cap < rx_len + chunk + 1 (payload plus trailing NUL). Discard remaining fragments after overflow until lws_is_final_fragment.
  • Set WebChat rx_buffer_size to WS_RX_BUFFER_SIZE (32KiB) so a full frame at MSG_MAX plus JSON envelope arrives in one RECEIVE.

Validation

  • CI=true make test_discord_helpers (includes exact-fill 4095+1 and two 64KiB fragments)
  • GCC ASan/UBSan on test_discord_helpers
  • GATEWAY=1 compile of discord.c, http.c, http_lws.c
Open in Web View Automation 

cursoragent and others added 2 commits September 7, 2026 11:15
discord_rx_append grew only when cap < rx_len+len, then wrote a NUL at
rx_len+len. Two 64KiB LWS fragments filled a doubled buffer exactly, so
the terminator was one byte past the heap block (typical READY payloads).

Co-authored-by: esadrianno <esadrianno@gmail.com>
…split

LWS delivers at most rx_buffer_size bytes per RECEIVE. The ws protocol used
256 with no fragment reassembly, so dashboard messages over ~220 characters
were parsed as incomplete JSON and dropped. Size the buffer to fit a full
WebChat frame (MSG_MAX plus JSON envelope). Distinct from outbound #62.

Co-authored-by: esadrianno <esadrianno@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant