Author: NeKon69
Date: 2026-02-06T02:51:08-05:00
New Revision: a8829d5a104cd9b180b101f27a387fa73ba76a10

URL: 
https://github.com/llvm/llvm-project/commit/a8829d5a104cd9b180b101f27a387fa73ba76a10
DIFF: 
https://github.com/llvm/llvm-project/commit/a8829d5a104cd9b180b101f27a387fa73ba76a10.diff

LOG: [clangd] Fix call hierarchy crash on malformed request (#179718)

The code for parsing a call hierarchy request was not using `ObjectMapper`
correctly: it was calling `map()` without first calling `operator bool()` to
check that an object was parsed at all.

Fixes #179109

Added: 
    

Modified: 
    clang-tools-extra/clangd/Protocol.cpp
    clang-tools-extra/clangd/test/call-hierarchy.test

Removed: 
    


################################################################################
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"}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to