aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2017-10-27 17:06:41 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2017-10-27 17:06:41 +0000
commit8ce68f41833f47d4f3e82bb550140465d6eef85a (patch)
tree25c837725915b4efa12dcfa20ab45c83102c6101
parent130858aa6b190d5220f912da53eeb258a45c0aee (diff)
[clangd] Don't crash on extremely large JSON messages.
Found by clangd-fuzzer. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@316774 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clangd/JSONRPCDispatcher.cpp9
-rw-r--r--test/clangd/too_large.test7
2 files changed, 16 insertions, 0 deletions
diff --git a/clangd/JSONRPCDispatcher.cpp b/clangd/JSONRPCDispatcher.cpp
index 5e48a071..0aa1f396 100644
--- a/clangd/JSONRPCDispatcher.cpp
+++ b/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/test/clangd/too_large.test b/test/clangd/too_large.test
new file mode 100644
index 00000000..60de8009
--- /dev/null
+++ b/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