]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Handle more cases of invalid secondary storage URLs
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 7 Jul 2022 10:25:57 +0000 (12:25 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 20 Aug 2022 11:59:29 +0000 (13:59 +0200)
(cherry picked from commit b41ac6a7bc42f56161f929dd1f2c8fdeb22493ad)

src/storage/Storage.cpp
test/suites/secondary_url.bash

index 0b28e8a2c0d534a41a0e0363f1ec78763e27a0d4..20f2a1131b858833696a732695862491c6382981 100644 (file)
@@ -121,12 +121,15 @@ parse_storage_config(const nonstd::string_view entry)
   }
 
   SecondaryStorageConfig result;
-  result.params.url = std::string(parts[0]);
-  // The Url class is parsing the URL object lazily; check if successful.
+  const auto url_str = std::string(parts[0]);
+  result.params.url = url_str;
+
+  // The Url class is parsing the URL object lazily. Check if the URL is valid
+  // now to avoid exceptions later.
   try {
-    std::ignore = result.params.url.host();
-  } catch (const Url::parse_error& e) {
-    throw core::Error("Cannot parse URL: {}", e.what());
+    std::ignore = result.params.url.str();
+  } catch (const std::exception& e) {
+    throw core::Error("Cannot parse URL {}: {}", url_str, e.what());
   }
 
   if (result.params.url.scheme().empty()) {
@@ -145,7 +148,6 @@ parse_storage_config(const nonstd::string_view entry)
     if (key == "read-only") {
       result.read_only = (value == "true");
     } else if (key == "shards") {
-      const auto url_str = result.params.url.str();
       if (url_str.find('*') == std::string::npos) {
         throw core::Error(R"(Missing "*" in URL when using shards: "{}")",
                           url_str);
index 74fe082947c7feb24b27dd3da81139a377aa1476..9c68645ddd1b36db33c67e7bf8a66eab760787f8 100644 (file)
@@ -30,4 +30,18 @@ SUITE_secondary_url() {
     export CCACHE_SECONDARY_STORAGE="/qwerty"
     $CCACHE_COMPILE -c test.c 2>stderr.log
     expect_contains stderr.log "URL scheme must not be empty"
+
+    # -------------------------------------------------------------------------
+    TEST "Reject user info defined but no host"
+
+    export CCACHE_SECONDARY_STORAGE="http://foo@"
+    $CCACHE_COMPILE -c test.c 2>stderr.log
+    expect_contains stderr.log "User info defined, but host is empty"
+
+    # -------------------------------------------------------------------------
+    TEST "Reject relative path with colon in first part"
+
+    export CCACHE_SECONDARY_STORAGE="file:foo:bar"
+    $CCACHE_COMPILE -c test.c 2>stderr.log
+    expect_contains stderr.log "The first segment of the relative path can't contain ':'"
 }