Commit 822a56f
fix(mcp): fix use-after-free in handle_manage_adr get path
yyjson_mut_obj_add_str stores the raw pointer without copying. Freeing
buf before yy_doc_to_str serializes the document causes yyjson to read
freed heap memory, producing garbage JSON. cbm_jsonrpc_format_response
then fails to parse the result field (res_doc == NULL), so "result" is
omitted from the JSON-RPC response and the MCP client hangs indefinitely.
Fix: hoist adr_buf to function scope (initialized NULL), remove the
premature free, and free it after yy_doc_to_str has serialized the doc.
Adds regression test tool_manage_adr_get_with_existing_adr that FAILS
before this fix and PASSES after it.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 75b5dcb commit 822a56f
2 files changed
+65
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1897 | 1897 | | |
1898 | 1898 | | |
1899 | 1899 | | |
| 1900 | + | |
1900 | 1901 | | |
1901 | 1902 | | |
1902 | 1903 | | |
| |||
1937 | 1938 | | |
1938 | 1939 | | |
1939 | 1940 | | |
1940 | | - | |
1941 | | - | |
1942 | | - | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
1943 | 1944 | | |
1944 | | - | |
1945 | | - | |
| 1945 | + | |
| 1946 | + | |
1946 | 1947 | | |
1947 | 1948 | | |
1948 | 1949 | | |
| |||
1959 | 1960 | | |
1960 | 1961 | | |
1961 | 1962 | | |
| 1963 | + | |
1962 | 1964 | | |
1963 | 1965 | | |
1964 | 1966 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
617 | 674 | | |
618 | 675 | | |
619 | 676 | | |
| |||
1273 | 1330 | | |
1274 | 1331 | | |
1275 | 1332 | | |
| 1333 | + | |
1276 | 1334 | | |
1277 | 1335 | | |
1278 | 1336 | | |
| |||
0 commit comments