summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-07-07 12:25:57 +0200
committerJoel Rosdahl <joel@rosdahl.net>2022-08-20 13:59:29 +0200
commit5d1eb8cf0e800dc426371413319ecc30b960e33c (patch)
tree50cd9f71f5b23ef410ee427fd8f350d99d933b26
parentafe1d25efd18709bae3b7f878bd05f098351b7be (diff)
downloadccache-5d1eb8cf0e800dc426371413319ecc30b960e33c.tar.gz
fix: Handle more cases of invalid secondary storage URLs
(cherry picked from commit b41ac6a7bc42f56161f929dd1f2c8fdeb22493ad)
-rw-r--r--src/storage/Storage.cpp14
-rw-r--r--test/suites/secondary_url.bash14
2 files changed, 22 insertions, 6 deletions
diff --git a/src/storage/Storage.cpp b/src/storage/Storage.cpp
index 0b28e8a2..20f2a113 100644
--- a/src/storage/Storage.cpp
+++ b/src/storage/Storage.cpp
@@ -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);
diff --git a/test/suites/secondary_url.bash b/test/suites/secondary_url.bash
index 74fe0829..9c68645d 100644
--- a/test/suites/secondary_url.bash
+++ b/test/suites/secondary_url.bash
@@ -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 ':'"
}