fix(asap): free inbound response payload once on envelope OOM - #93
Closed
cursor[bot] wants to merge 1 commit into
Closed
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
fill_response_envelope attached the payload cJSON then deleted it and called asap_envelope_clear, which deleted the same object. Unauthenticated POST /asap state.query and task.cancel reach this path; required-field strdup failure is a heap double-free. Co-authored-by: esadrianno <esadrianno@gmail.com>
5 tasks
Collaborator
|
Superseded by #97 (rewrite against |
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.
Summary
fill_response_envelopenow transfers payload ownership to the envelope and letsasap_envelope_clearfree it once when a required fieldstrdupfails.senderafter a validtask.cancelparse so the same post-attach cleanup path runs without a malloc hook.Bug
On
main@d367477,fill_response_envelopeassignedout->payload = payloadthen on missingid/asap_version/sender/recipient/payload_typecalledcJSON_Delete(payload)andasap_envelope_clear(out), which deletesout->payloadagain.Trigger (production HTTP): unauthenticated
POST /asapwithpayload_typestate.queryortask.cancel(parser requires sender/recipient, so those pointers are present). After the payload is attached, any requiredstrdupfailure (OOM; heap pressure from concurrent/asapbodies thatmalloc(ASAP_BODY_MAX+1)) takes the cleanup path. AddressSanitizer on the unit path reports heap-use-after-free incJSON_Deleteviaasap_envelope_clear.Impact: heap double-free / UAF on the gateway HTTP thread (crash or memory corruption).
Distinct from #84 (client JSON-RPC
iddouble-free) and #86 (POST body size cap).Test plan
make test_asap_server && ./build/test_asap_server./build/test_asap_server: previously aborted with heap-use-after-free atfill_response_envelope; now exits 0./build/test_asap_envelope,./build/test_asap_invoke,./build/test_asap_client,./build/test_asap_logChangelog