Author: d0k Date: Thu Oct 26 03:36:20 2017 New Revision: 316652 URL: http://llvm.org/viewvc/llvm-project?rev=316652&view=rev Log: [clangd] Don't crash on empty textDocument/didChange.
Found by clangd-fuzzer. Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/test/clangd/protocol.test Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=316652&r1=316651&r2=316652&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Oct 26 03:36:20 2017 @@ -73,6 +73,8 @@ void ClangdLSPServer::onDocumentDidOpen( 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); Modified: clang-tools-extra/trunk/test/clangd/protocol.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/protocol.test?rev=316652&r1=316651&r2=316652&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/protocol.test (original) +++ clang-tools-extra/trunk/test/clangd/protocol.test Thu Oct 26 03:36:20 2017 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits