Skip to content

ws: set seen_close only after the whole CLOSE frame - #23627

Closed
mvanslobbe wants to merge 1 commit into
curl:masterfrom
mvanslobbe:fix/ws-close-truncated
Closed

mvanslobbe wants to merge 1 commit into
curl:masterfrom
mvanslobbe:fix/ws-close-truncated

Conversation

@mvanslobbe

Copy link
Copy Markdown
Contributor

Since ed24670 (#23579), the decoder sets seen_close as soon as it has parsed the header of a CLOSE frame. ws_cw_write() stops receiving once that flag is set and its buffer is empty, so when the CLOSE payload arrives over more than one read, only the first part is passed on and the rest of the status code and reason is never read. curl then prints part of the frame and still exits 0. For example, a server sending close code 1001 with a reason, split after the first payload byte, gives only the byte 0x03 on stdout.

This keeps the early stop from ed24670, but sets the flag only once the decoder has passed on the complete CLOSE frame. The "too big" check on the CLOSE header stays where it was.

Test 2312 has the test server write 20 bytes at a time, with the headers sized so that the CLOSE frame starts 3 bytes before a write boundary and its payload arrives in separate reads. It fails on master and passes with the fix.

ed24670 is not in a release yet, so this does not affect 8.23.x.

Reported earlier as a comment on #23579.

AI disclosure

I found this with a fuzzer written with the help of Claude Code. I reviewed and tested the fix and the test myself.

The flag was set when the CLOSE frame header was parsed. When the
payload was split over several reads, the transfer stopped receiving
as soon as the first part had been decoded, and the rest of the status
code and reason was never read.

Set the flag once the decoder has passed on the complete frame.

Add test 2312, which makes the test server deliver the CLOSE payload in
separate reads.

Follow-up to ed24670

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The localized decoder fix preserves error handling and zero-length frame completion, with a targeted regression test and no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR fixes truncated WebSocket CLOSE payloads by marking the frame as received only after its complete payload has been passed on.

Changes:

  • Moves seen_close assignment to frame completion while preserving the oversized-CLOSE check.
  • Adds and registers a regression test that splits a CLOSE payload across reads.
File Description
tests/​data/​test2312 Tests complete delivery of a CLOSE payload split across reads.
tests/​data/​Makefile.am Registers test 2312.
lib/​ws.c Defers seen_close until the complete CLOSE frame has been passed on.

Review effort: Balanced

@bagder bagder closed this in 4e80002 Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants