[clang-tools-extra] r316774 - [clangd] Don't crash on extremely large JSON messages.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 10:06:41 PDT 2017


Author: d0k
Date: Fri Oct 27 10:06:41 2017
New Revision: 316774

URL: http://llvm.org/viewvc/llvm-project?rev=316774&view=rev
Log:
[clangd] Don't crash on extremely large JSON messages.

Found by clangd-fuzzer.

Added:
    clang-tools-extra/trunk/test/clangd/too_large.test
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=316774&r1=316773&r2=316774&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Fri Oct 27 10:06:41 2017
@@ -196,6 +196,15 @@ void clangd::runLanguageServerLoop(std::
       }
     }
 
+    // Guard against large messages. This is usually a bug in the client code
+    // and we don't want to crash downstream because of it.
+    if (ContentLength > 1 << 30) { // 1024M
+      In.ignore(ContentLength);
+      Out.log("Skipped overly large message of " + Twine(ContentLength) +
+              " bytes.\n");
+      continue;
+    }
+
     if (ContentLength > 0) {
       // Now read the JSON. Insert a trailing null byte as required by the YAML
       // parser.

Added: clang-tools-extra/trunk/test/clangd/too_large.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/too_large.test?rev=316774&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/too_large.test (added)
+++ clang-tools-extra/trunk/test/clangd/too_large.test Fri Oct 27 10:06:41 2017
@@ -0,0 +1,7 @@
+# RUN: not clangd -run-synchronously < %s 2>&1 | FileCheck -check-prefix=STDERR %s
+# vim: fileformat=dos
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 2147483648
+
+# STDERR: Skipped overly large message




More information about the cfe-commits mailing list