Repository navigation
ws: set seen_close only after the whole CLOSE frame - #23627
Closed
mvanslobbe wants to merge 1 commit into
Closed
mvanslobbe wants to merge 1 commit into
mvanslobbe wants to merge 1 commit into
Conversation
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
There was a problem hiding this comment.
🟢 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_closeassignment 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since ed24670 (#23579), the decoder sets
seen_closeas 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.