From b560a9a1b83523e16c16dfe430aa5f46fd958de5 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 26 Oct 2017 10:36:20 +0000 Subject: [PATCH] [clangd] Don't crash on empty textDocument/didChange. Found by clangd-fuzzer. llvm-svn: 316652 --- clang-tools-extra/clangd/ClangdLSPServer.cpp | 2 ++ clang-tools-extra/test/clangd/protocol.test | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index ca95fd8fdefc..3b68f2a6dc15 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -73,6 +73,8 @@ void ClangdLSPServer::onDocumentDidOpen(Ctx C, void ClangdLSPServer::onDocumentDidChange(Ctx C, DidChangeTextDocumentParams &Params) { + if (Params.contentChanges.size() != 1) + return C.replyError(-32602, "can only apply one change at a time"); // We only support full syncing right now. Server.addDocument(Params.textDocument.uri.file, Params.contentChanges[0].text); diff --git a/clang-tools-extra/test/clangd/protocol.test b/clang-tools-extra/test/clangd/protocol.test index 4dd5508faace..61fa90c86d13 100644 --- a/clang-tools-extra/test/clangd/protocol.test +++ b/clang-tools-extra/test/clangd/protocol.test @@ -26,6 +26,10 @@ Content-Length: 246 {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n fake f;\n f.\n}\n"}}} +Content-Length: 104 + +{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp"}}} + Content-Type: application/vscode-jsonrpc; charset-utf-8 Content-Length: 146