From 171c469927b1b7c5a4f81f113081985e7dc84597 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 25 May 2025 14:46:45 +0200 Subject: edsp: Do not skip lines (fixes Architecture reading) We skipped the Architecture: line because when the outer loop got to it, the inner loop started and read the next line after it. Get rid of the nested loop instead, and first run a loop to find the request line, and then a second loop to parse the request flags. An alternative would be to use a combined loop that supports non-compliant protocol implementations, but that's harder to read and we don't expect there to be any especially on the request side. --- apt-pkg/edsp.cc | 62 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 73c6889e5..6c9c3f3ee 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -595,46 +595,46 @@ bool EDSP::ReadRequest(int const input, std::list &install, continue; // The first Tag must be a request, so search for it if (LineStartsWithAndStrip(line, "Request:")) - continue; + break; + } - while (ReadLine(input, line) == true) + while (ReadLine(input, line)) + { + // empty lines are the end of the request + if (line.empty() == true) { - // empty lines are the end of the request - if (line.empty() == true) - { - // Clear the architecture cache, since we may have set different ones - APT::Configuration::getArchitectures(false); - return true; - } + // Clear the architecture cache, since we may have set different ones + APT::Configuration::getArchitectures(false); + return true; + } - std::list *request = NULL; - if (LineStartsWithAndStrip(line, "Install:")) - request = &install; - else if (LineStartsWithAndStrip(line, "Remove:")) - request = &remove; - else if (ReadFlag(flags, line, "Upgrade:", (Request::UPGRADE_ALL | Request::FORBID_REMOVE | Request::FORBID_NEW_INSTALL)) || + std::list *request = NULL; + if (LineStartsWithAndStrip(line, "Install:")) + request = &install; + else if (LineStartsWithAndStrip(line, "Remove:")) + request = &remove; + else if (ReadFlag(flags, line, "Upgrade:", (Request::UPGRADE_ALL | Request::FORBID_REMOVE | Request::FORBID_NEW_INSTALL)) || ReadFlag(flags, line, "Dist-Upgrade:", Request::UPGRADE_ALL) || ReadFlag(flags, line, "Upgrade-All:", Request::UPGRADE_ALL) || ReadFlag(flags, line, "Forbid-New-Install:", Request::FORBID_NEW_INSTALL) || ReadFlag(flags, line, "Forbid-Remove:", Request::FORBID_REMOVE) || ReadFlag(flags, line, "Autoremove:", Request::AUTOREMOVE)) - ; - else if (LineStartsWithAndStrip(line, "Architecture:")) - _config->Set("APT::Architecture", line); - else if (LineStartsWithAndStrip(line, "Architectures:")) - _config->Set("APT::Architectures", SubstVar(line, " ", ",")); - else if (LineStartsWithAndStrip(line, "Machine-ID")) - _config->Set("APT::Machine-ID", line); - else if (LineStartsWithAndStrip(line, "Solver:")) - ; // purely informational line - else - _error->Warning("Unknown line in EDSP Request stanza: %s", line.c_str()); + ; + else if (LineStartsWithAndStrip(line, "Architecture:")) + _config->Set("APT::Architecture", line); + else if (LineStartsWithAndStrip(line, "Architectures:")) + _config->Set("APT::Architectures", SubstVar(line, " ", ",")); + else if (LineStartsWithAndStrip(line, "Machine-ID")) + _config->Set("APT::Machine-ID", line); + else if (LineStartsWithAndStrip(line, "Solver:")) + ; // purely informational line + else + _error->Warning("Unknown line in EDSP Request stanza: %s", line.c_str()); - if (request == NULL) - continue; - auto const pkgs = VectorizeString(line, ' '); - std::move(pkgs.begin(), pkgs.end(), std::back_inserter(*request)); - } + if (request == NULL) + continue; + auto const pkgs = VectorizeString(line, ' '); + std::move(pkgs.begin(), pkgs.end(), std::back_inserter(*request)); } return false; } /*}}}*/ -- cgit v1.2.3-70-g09d2