[clangd] Don't crash on empty textDocument/didChange.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 26 Oct 2017 10:36:20 +0000 (10:36 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 26 Oct 2017 10:36:20 +0000 (10:36 +0000)
Found by clangd-fuzzer.

llvm-svn: 316652

clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/test/clangd/protocol.test

index ca95fd8..3b68f2a 100644 (file)
@@ -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);
index 4dd5508..61fa90c 100644 (file)
@@ -26,6 +26,10 @@ Content-Length: 246
 \r
 {"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"}}}\r
 \r
+Content-Length: 104\r
+\r
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp"}}}\r
+\r
 Content-Type: application/vscode-jsonrpc; charset-utf-8\r
 Content-Length: 146\r
 \r