From 9de2fd4d117e57824f4a0795efa7379995a804cb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 25 Feb 2016 16:46:42 +0100 Subject: [PATCH] Fix crash with empty architecture list If the architecture list is empty somehow, fail normally. LP: #1549819 --- apt-pkg/pkgcache.cc | 10 ++++++---- .../test-ubuntu-bug-1549819-empty-arch-list | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100755 test/integration/test-ubuntu-bug-1549819-empty-arch-list diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index c9c338e1e..503f85657 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -184,10 +184,12 @@ bool pkgCache::ReMap(bool const &Errorchecks) // Check the architecture std::vector archs = APT::Configuration::getArchitectures(); - std::vector::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()); diff --git a/test/integration/test-ubuntu-bug-1549819-empty-arch-list b/test/integration/test-ubuntu-bug-1549819-empty-arch-list new file mode 100755 index 000000000..5e1c6ce7e --- /dev/null +++ b/test/integration/test-ubuntu-bug-1549819-empty-arch-list @@ -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 -- 2.45.2