From b3a5bbe234d4206b7736bca2ca7f56feaa92f5ff Mon Sep 17 00:00:00 2001 From: Troy Varney Date: Tue, 26 Apr 2022 12:08:19 -0500 Subject: 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. --- methods/mirror.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'methods') 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 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 const &baseuris, /*{{{*/ -- cgit v1.2.3-70-g09d2