[clang-tools-extra] r316770 - [clangd] Harden clangd a bit against garbage input.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 09:33:15 PDT 2017


Author: d0k
Date: Fri Oct 27 09:33:15 2017
New Revision: 316770

URL: http://llvm.org/viewvc/llvm-project?rev=316770&view=rev
Log:
[clangd] Harden clangd a bit against garbage input.

There can be nullptrs here if the YAML fails to parse. Found by
clangd-fuzzer!

Modified:
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=316770&r1=316769&r2=316770&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Fri Oct 27 09:33:15 2017
@@ -88,11 +88,7 @@ bool JSONRPCDispatcher::call(StringRef C
   if (Doc == YAMLStream.end())
     return false;
 
-  auto *Root = Doc->getRoot();
-  if (!Root)
-    return false;
-
-  auto *Object = dyn_cast<llvm::yaml::MappingNode>(Root);
+  auto *Object = dyn_cast_or_null<llvm::yaml::MappingNode>(Doc->getRoot());
   if (!Object)
     return false;
 
@@ -101,7 +97,8 @@ bool JSONRPCDispatcher::call(StringRef C
   llvm::yaml::MappingNode *Params = nullptr;
   llvm::yaml::ScalarNode *Id = nullptr;
   for (auto &NextKeyValue : *Object) {
-    auto *KeyString = dyn_cast<llvm::yaml::ScalarNode>(NextKeyValue.getKey());
+    auto *KeyString =
+        dyn_cast_or_null<llvm::yaml::ScalarNode>(NextKeyValue.getKey());
     if (!KeyString)
       return false;
 




More information about the cfe-commits mailing list