Repository navigation
Conversation
The HTTP server (software/httpd, separate repo) now calls a response BodyCB with (ctx, NULL, -1) when a connection ends before the reply was sent to the end, so the body source can release its context. Until now it never did, and every reply abandoned by its client leaked the body: about 1.1 KB for a JSON reply, up to 64 KB for `GET /v1/machine:readmem?address=0&length=65536`, the whole VCD for a measure, and a static file's FILE*. Any LAN client can do this with no login: send the request, read nothing, close. The next client that landed on the same connection slot could also be sent the previous client's unsent body behind its own 404. This commit: - api/routes.h stream_body: on len < 0, delete the StreamRamFile and return 0. It serves the JSON, HTML and attachment replies of ResponseWrapper. Without it the new abort call would read into a NULL buffer. - software/httpd: bump to the MicroHttpServer commit that releases res.BodyCB on close, resets the response on accept and closes the FILE* in filestream_out. That commit must be merged in the httpd repo first; the gitlink here points at it. - target/pc/linux/httpdbody (new): a loopback test of the server with a client that abandons a reply, built with AddressSanitizer and leak detection, plus a test of ResponseWrapper's three reply kinds being abandoned. `make host_tests` runs it. With the old httpd the socket test fails its three cases (three live response bodies after three abandoned replies; the second client gets 8192 bytes of the first client's body instead of a 45 byte 404; one file descriptor held). routes_body_test fails on its own without the routes.h change (AddressSanitizer: memcpy overlap, the NULL buffer). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Collaborator
Conflict resolved: Makefile host_tests target. Master added the software/userinterface/tests run, this branch added target/pc/linux/httpdbody; both lines kept. software/httpd gitlink untouched by master, stays at the MicroHttpServer commit of this PR. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The CI image has a library preloaded. An AddressSanitizer binary started
that way refuses to run ("ASan runtime does not come first in initial
library list"), so `make host_tests` failed at httpdbody before the test
ran. Start both test programs with `env -u LD_PRELOAD`, as the other
AddressSanitizer tests in the repository already do. Leak detection stays on.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Contributor
Author
|
@chrisgleissner The conflicts are resolved: master is merged in, and CI is green at 5ccc41c. The CI failure that showed first was not from the merge. The new httpd body tests are built with AddressSanitizer and the CI image sets The PR stays in draft only because its submodule pointer needs GideonZ/MicroHttpServer#8 merged first. Once that is in, I will add a commit that points at the merged commit and mark this ready. Written with Claude Fable 5.2 in Claude Code. |
Collaborator
|
@JC-000 That other PR is merged now. Could you please update this PR as needed, then respond here once it is ready to be merged? Thank you. |
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.
Fixes #1115
Depends on GideonZ/MicroHttpServer#GideonZ/MicroHttpServer#8. The gitlink bump in this PR points at that commit; merge that PR first; this PR will then be updated to point at the merged commit. Neither half works alone: the routes.h change by itself is inert, and the submodule change by itself makes
stream_bodyread into a NULL buffer.The HTTP server now calls a response
BodyCBwith(ctx, NULL, -1)when a connection ends before the reply was sent to the end, so the body source can release its context. Until now it never did, and every reply abandoned by its client leaked the body: about 1.1 KB for a JSON reply, up to 64 KB forGET /v1/machine:readmem?address=0&length=65536, the whole VCD for a measure, and a static file'sFILE*. Any LAN client can do this with no login (no network password set): send the request, read nothing, close. The next client that landed on the same connection slot could also be sent the previous client's unsent body behind its own 404.Measured loss per aborted readmem: C64 Ultimate 66,994 B, Ultimate 64 Elite about 66,400 B; about 79 aborted requests (extrapolated) exhaust a fresh heap (about 5.3 MB free) on either.
Change
stream_body: onlen < 0, delete theStreamRamFileand return 0. It serves the JSON, HTML and attachment replies ofResponseWrapper.res.BodyCBon close, resets the response on accept and closes theFILE*infilestream_out.make host_tests: a loopback test of the server with a client that abandons a reply (AddressSanitizer, leak detection), and a test ofResponseWrapper's three reply kinds being abandoned.Tests (host, container)
httpd_body_test: FAILresponse_body_released_on_client_abort(3 response bodies still allocated), FAILnext_client_gets_only_its_own_reply(8192 bytes instead of a 45 byte 404), FAILstatic_file_closed_on_client_abort(1 file descriptor held).routes_body_test: AddressSanitizer memcpy-param-overlap (NULL buffer).httpd_body: 0 failed,routes_body: 0 failed.The 64 KB readmem figure was measured end to end on both devices; the JSON-reply, measure and static-file costs come from reading the code. The stale-body bleed is covered by the host loopback test only.
Written with Claude Sonnet 5.5 in Claude Code; reviewed adversarially by separate Claude Opus 5.5 sessions before posting.
🤖 Generated with Claude Code