summaryrefslogtreecommitdiff
path: root/methods/mirror.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2022-04-28 16:44:13 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2024-11-22 12:40:10 +0000
commitafc7b0dbf1114f3d723ff0e1ab9d0796cd799970 (patch)
tree90f5cc06822d73102b9ec3620ab01793d40ad0d8 /methods/mirror.cc
parentd9601bce6e1fa61cbb3dc4d66e5492f9885eef8f (diff)
Do not assume mirror-URIs end in a filename causing a hang
In practice most of them will, but making the acquire process hang in response if they don't seems like an overly excessive response if we can just support it gracefully to reply with an error (or actually succeed in the unlikely event this URI is actually correct).
Diffstat (limited to 'methods/mirror.cc')
-rw-r--r--methods/mirror.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/methods/mirror.cc b/methods/mirror.cc
index 787e4c7d5..5781ebcf0 100644
--- a/methods/mirror.cc
+++ b/methods/mirror.cc
@@ -326,7 +326,11 @@ std::string MirrorMethod::GetMirrorFileURI(std::string const &Message, FetchItem
{
if (APT::String::Startswith(Itm->Uri, uristr))
{
- uristr.erase(uristr.length() - 1); // remove the ending '/'
+ if (::URI uri{uristr}; uri.Path.length() > 1 && APT::String::Endswith(uri.Path, "/"))
+ {
+ uri.Path.erase(uri.Path.length() - 1); // remove the ending '/'
+ uristr = uri;
+ }
auto const colon = uristr.find(':');
if (unlikely(colon == std::string::npos))
continue;
@@ -375,7 +379,10 @@ bool MirrorMethod::URIAcquire(std::string const &Message, FetchItem *Itm) /*{{{*
msgCache[Itm->Uri] = Message;
MirrorListInfo info;
info.state = REQUESTED;
- info.baseuri = mirrorfileuri + '/';
+ if (not APT::String::Endswith(mirrorfileuri, "/"))
+ info.baseuri = mirrorfileuri + '/';
+ else
+ info.baseuri = mirrorfileuri;
auto const colon = info.baseuri.find(':');
if (unlikely(colon == std::string::npos))
return false;