diff options
-rw-r--r-- | clang-tools-extra/clangd/JSONRPCDispatcher.cpp | 9 | ||||
-rw-r--r-- | clang-tools-extra/test/clangd/too_large.test | 7 |
2 files changed, 16 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp index 5e48a071094..0aa1f396a9e 100644 --- a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp +++ b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp @@ -196,6 +196,15 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out, } } + // 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. diff --git a/clang-tools-extra/test/clangd/too_large.test b/clang-tools-extra/test/clangd/too_large.test new file mode 100644 index 00000000000..60de800986c --- /dev/null +++ b/clang-tools-extra/test/clangd/too_large.test @@ -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
|