diff options
author | Troy Varney <tvarney@cloudflare.com> | 2022-04-26 12:08:19 -0500 |
---|---|---|
committer | Troy Varney <tvarney@cloudflare.com> | 2022-04-28 12:43:34 -0500 |
commit | b3a5bbe234d4206b7736bca2ca7f56feaa92f5ff (patch) | |
tree | 570f1e833f61eb4d7a4229797bb836a7f696e527 /methods | |
parent | 51bcb140eacd3c42b2b82d3d8946bf236858bbf1 (diff) |
Fix mirror method dequeuing incorrect items
When the mirror method handles a URI Acquire from apt for a mirror list
it already has, it calls the `RedirectItem` function directly. This
function assumes that the item being redirected is at the head of the
queue, and as such calls `Dequeue` to remove it from the queue. This
resulted in incorrect items being removed from the queue when this
branch is taken and the queue was already non-empty, as the item to be
handled in this case is actually the last item in the queue.
This changes `RedirectItem` to properly remove the item passed to it
instead of calling Dequeue.
Diffstat (limited to 'methods')
-rw-r--r-- | methods/mirror.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/methods/mirror.cc b/methods/mirror.cc index 5a34d8297..787e4c7d5 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -145,7 +145,7 @@ void MirrorMethod::RedirectItem(MirrorListInfo const &info, FetchItem *const Itm std::string const path = Itm->Uri.substr(info.baseuri.length()); std::string altMirrors; std::unordered_map<std::string, std::string> fields; - fields.emplace("URI", Queue->Uri); + fields.emplace("URI", Itm->Uri); for (auto curMirror = possMirrors.cbegin(); curMirror != possMirrors.cend(); ++curMirror) { std::string mirror = curMirror->uri; @@ -161,7 +161,19 @@ void MirrorMethod::RedirectItem(MirrorListInfo const &info, FetchItem *const Itm } fields.emplace("Alternate-URIs", altMirrors); SendMessage("103 Redirect", std::move(fields)); - Dequeue(); + + // Remove Itm from the queue, then delete + if (Queue == Itm) + Queue = Itm->Next; + else + { + FetchItem *previous = Queue; + while (previous->Next != Itm) + previous = previous->Next; + + previous->Next = Itm->Next; + } + delete Itm; } /*}}}*/ void MirrorMethod::DealWithPendingItems(std::vector<std::string> const &baseuris, /*{{{*/ |