[clang-tools-extra] 43637c0 - Fix crash when an invalid URI is parsed and error handling is attempted

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 7 03:38:25 PDT 2021


Author: crr0004
Date: 2021-04-07T12:32:33+02:00
New Revision: 43637c0dfeebcf4a4fcbb331f1094662e8882430

URL: https://github.com/llvm/llvm-project/commit/43637c0dfeebcf4a4fcbb331f1094662e8882430
DIFF: https://github.com/llvm/llvm-project/commit/43637c0dfeebcf4a4fcbb331f1094662e8882430.diff

LOG: Fix crash when an invalid URI is parsed and error handling is attempted

When you pass in a payload with an invalid URI in a build with assertions enabled, it will crash.
Consuming the error from the failed URI parse prevents the error.

The crash is caused by the [llvm::expected](https://llvm.org/doxygen/classllvm_1_1Expected.html) having protection around trying to deconstruct without consuming the error first.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D99872

Added: 
    

Modified: 
    clang-tools-extra/clangd/Protocol.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 099c8531d341..de2f34c6bd84 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -70,6 +70,7 @@ bool fromJSON(const llvm::json::Value &E, URIForFile &R, llvm::json::Path P) {
   if (auto S = E.getAsString()) {
     auto Parsed = URI::parse(*S);
     if (!Parsed) {
+      consumeError(Parsed.takeError());
       P.report("failed to parse URI");
       return false;
     }


        


More information about the cfe-commits mailing list