fix(asap): avoid double-free on malformed JSON-RPC results - #84
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(asap): avoid double-free on malformed JSON-RPC results#84cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
parse_fail already frees the duplicated request id when asap_envelope_from_object rejects a result envelope. The JSON-RPC response parser deleted it again, so HTTP 200 with a missing payload (or other required field) crashed asap_invoke / asap_client_send_task. Co-authored-by: esadrianno <esadrianno@gmail.com>
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
HIGH heap use-after-free / double-free on the ASAP client JSON-RPC response path — distinct from inbound-server PRs #53/#60/#61/#64.
asap_envelope_from_object/parse_fail(src/asap/envelope.c:104) alreadycJSON_Deletes the duplicated JSON-RPCidwhen a result envelope is missing required fields.asap_envelope_parse_jsonrpc_responsethen deleted the same pointer again (src/asap/envelope.c:331ona057f0e).Concrete trigger
asap_invoke/asap_client_send_taskreceives HTTP 200 with a JSON-RPCresultobject that lackspayload(or another required string), e.g. a hostile registrybase_urlor malicious remote agent:{"jsonrpc":"2.0","id":"1","result":{"id":"t1","asap_version":"2.1","sender":"a","recipient":"b","payload_type":"task.response"}}Inbound
asap_envelope_parsedoes not double-free (it leavesrpc_idtoparse_fail). Existing tests only covered a valid result and a top-level JSON-RPCerrorobject.Impact
Heap use-after-free → process crash; possible allocator corruption on the agent daemon.
ASan confirmed:
cJSON_Deleteinparse_jsonrpc_responseafterparse_failviafrom_object(missingpayload).Fix
Do not
cJSON_Delete(rpc_id)on the from_object-failure path (match inbound parse). Document thatrpc_idis consumed on validation failure.Test plan
test_parse_response_missing_payload— unit parse of HTTP 200 result withoutpayloadtest_live_http_malformed_result_envelope—asap_client_send_taskagainst a 200 with the same bodytest_asap_clientunder AddressSanitizer