llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-tools-extra Author: None (NeKon69) <details> <summary>Changes</summary> [clangd] Fix clangd crash on invalid parameters in incoming/outgoing calls Previous code that handled json parsing from incoming/outgoing calls did not account for the fact that input can be malformed (e.g. []). My change fixes that by checking if the `ObjectMapper` is valid before doing anything with it. Also added tests to prevent that from happening again. Fixes #<!-- -->179109 --- Full diff: https://github.com/llvm/llvm-project/pull/179718.diff 2 Files Affected: - (modified) clang-tools-extra/clangd/Protocol.cpp (+2-2) - (modified) clang-tools-extra/clangd/test/call-hierarchy.test (+13-1) ``````````diff diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index 9926f2dd63de5..a697486d48f9c 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -1511,7 +1511,7 @@ bool fromJSON(const llvm::json::Value &Params, CallHierarchyItem &I, bool fromJSON(const llvm::json::Value &Params, CallHierarchyIncomingCallsParams &C, llvm::json::Path P) { llvm::json::ObjectMapper O(Params, P); - return O.map("item", C.item); + return O && O.map("item", C.item); } llvm::json::Value toJSON(const CallHierarchyIncomingCall &C) { @@ -1521,7 +1521,7 @@ llvm::json::Value toJSON(const CallHierarchyIncomingCall &C) { bool fromJSON(const llvm::json::Value &Params, CallHierarchyOutgoingCallsParams &C, llvm::json::Path P) { llvm::json::ObjectMapper O(Params, P); - return O.map("item", C.item); + return O && O.map("item", C.item); } llvm::json::Value toJSON(const CallHierarchyOutgoingCall &C) { diff --git a/clang-tools-extra/clangd/test/call-hierarchy.test b/clang-tools-extra/clangd/test/call-hierarchy.test index 6548ea0068a8d..f0d57b60421a4 100644 --- a/clang-tools-extra/clangd/test/call-hierarchy.test +++ b/clang-tools-extra/clangd/test/call-hierarchy.test @@ -34,6 +34,18 @@ # CHECK-NEXT: "uri": "file://{{.*}}/clangd-test/main.cpp" # CHECK-NEXT: } --- -{"jsonrpc":"2.0","id":3,"method":"shutdown"} +{"jsonrpc":"2.0","id":3,"method":"callHierarchy/incomingCalls","params":[]} +# CHECK: "error": { +# CHECK-NEXT: "code": -32602, +# CHECK-NEXT: "message": "failed to decode callHierarchy/incomingCalls request: expected object" +# CHECK-NEXT: } +--- +{"jsonrpc":"2.0","id":4,"method":"callHierarchy/outgoingCalls","params":4} +# CHECK: "error": { +# CHECK-NEXT: "code": -32602, +# CHECK-NEXT: "message": "failed to decode callHierarchy/outgoingCalls request: expected object" +# CHECK-NEXT: } +--- +{"jsonrpc":"2.0","id":5,"method":"shutdown"} --- {"jsonrpc":"2.0","method":"exit"} `````````` </details> https://github.com/llvm/llvm-project/pull/179718 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
