diff options
author | David Kalnischkies <david@kalnischkies.de> | 2016-05-03 23:22:53 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-05-10 20:53:16 +0200 |
commit | 910accc32542b5e99bdf146e55afdc0c48d17a6e (patch) | |
tree | e5f853ad97da82bee5bf44fedd77dfcb08afcedd /apt-pkg | |
parent | f5b1b479cfcebcac2f4ac1b9266c1d871d3cd988 (diff) |
allow redirection for items without a space in the desc again
Broken in a4b8112b19763cbd2c12b81d55bc7d43a591d610.
If an item has a description which includes no space and is redirected
to another mirror the code which wants to rewrite the description
expects a space in there, but can't find it and the unguarded substr
command on the string will fail with an exception thrown…
Guarding it properly and everything is fine.
(cherry picked from commit 84ac6edfabe1c92d67e8d441e04216ad33c89165)
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/acquire-worker.cc | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index ca1fd4836..6cf6c856e 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -273,16 +273,19 @@ bool pkgAcquire::Worker::RunMessages() // if we change site, treat it as a mirror change if (URI::SiteOnly(NewURI) != URI::SiteOnly(desc.URI)) { - std::string const OldSite = desc.Description.substr(0, desc.Description.find(" ")); - if (likely(APT::String::Startswith(desc.URI, OldSite))) + auto const firstSpace = desc.Description.find(" "); + if (firstSpace != std::string::npos) { - std::string const OldExtra = desc.URI.substr(OldSite.length() + 1); - if (likely(APT::String::Endswith(NewURI, OldExtra))) + std::string const OldSite = desc.Description.substr(0, firstSpace); + if (likely(APT::String::Startswith(desc.URI, OldSite))) { - std::string const NewSite = NewURI.substr(0, NewURI.length() - OldExtra.length()); - Owner->UsedMirror = URI::ArchiveOnly(NewSite); - if (desc.Description.find(" ") != string::npos) - desc.Description.replace(0, desc.Description.find(" "), Owner->UsedMirror); + std::string const OldExtra = desc.URI.substr(OldSite.length() + 1); + if (likely(APT::String::Endswith(NewURI, OldExtra))) + { + std::string const NewSite = NewURI.substr(0, NewURI.length() - OldExtra.length()); + Owner->UsedMirror = URI::ArchiveOnly(NewSite); + desc.Description.replace(0, firstSpace, Owner->UsedMirror); + } } } } |