]> git.saurik.com Git - apt.git/commitdiff
allow redirection for items without a space in the desc again
authorDavid Kalnischkies <david@kalnischkies.de>
Tue, 3 May 2016 21:22:53 +0000 (23:22 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Tue, 3 May 2016 21:37:43 +0000 (23:37 +0200)
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.

apt-pkg/acquire-worker.cc
test/integration/test-handle-redirect-as-used-mirror-change

index 69ca6a28e19a8740c72634bb1ef2dcbae9775648..2ad0eda7f581308828843129670b059ec4e42417 100644 (file)
@@ -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);
+                       }
                     }
                  }
               }
index e9370930aac180ae5ce274ed423e55ef061810da..f4a2403236460cd90c8925f41ce33981e3028899 100755 (executable)
@@ -37,3 +37,6 @@ Location: http://0.0.0.0:${APTHTTPPORT}/dists/unstable/InRelease
 Location: http://0.0.0.0:${APTHTTPPORT}/dists/unstable/main/source/Sources.gz
 Location: http://0.0.0.0:${APTHTTPPORT}/dists/unstable/main/binary-all/Packages.gz
 Location: http://0.0.0.0:${APTHTTPPORT}/dists/unstable/main/i18n/Translation-en.gz" grep '^Location:' aptarchive/webserver.log
+
+testsuccess apthelper download-file "http://localhost:${APTHTTPPORT}/redirectme/dists/unstable/InRelease" inrelease
+testsuccess test -s inrelease