Browse Source

Fix crash with empty architecture list

If the architecture list is empty somehow, fail normally.

LP: #1549819
tags/debian/1.2.4
Julian Andres Klode 5 years ago
parent
commit
9de2fd4d11
2 changed files with 19 additions and 4 deletions
  1. +6
    -4
      apt-pkg/pkgcache.cc
  2. +13
    -0
      test/integration/test-ubuntu-bug-1549819-empty-arch-list

+ 6
- 4
apt-pkg/pkgcache.cc View File

@@ -184,10 +184,12 @@ bool pkgCache::ReMap(bool const &Errorchecks)

// Check the architecture
std::vector<std::string> archs = APT::Configuration::getArchitectures();
std::vector<std::string>::const_iterator a = archs.begin();
std::string list = *a;
for (++a; a != archs.end(); ++a)
list.append(",").append(*a);
std::string list = "";
for (auto const & arch : archs) {
if (!list.empty())
list.append(",");
list.append(arch);
}
if (_config->Find("APT::Architecture") != StrP + HeaderP->Architecture ||
list != StrP + HeaderP->GetArchitectures())
return _error->Error(_("The package cache was built for different architectures: %s vs %s"), StrP + HeaderP->GetArchitectures(), list.c_str());


+ 13
- 0
test/integration/test-ubuntu-bug-1549819-empty-arch-list View File

@@ -0,0 +1,13 @@
#!/bin/sh
set -e

TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"
setupenvironment
configarchitecture ""
echo 'APT::Architecture "";' > rootdir/etc/apt/apt.conf
echo 'APT::Architectures:: "";' >> rootdir/etc/apt/apt.conf
setupaptarchive

# test success
testsuccess aptcache -c rootdir/etc/apt/apt.conf gencaches -o debug::NoLocking=1

Loading…
Cancel
Save