diff options
author | Julian Andres Klode <jak@debian.org> | 2016-07-05 08:21:28 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-07-05 08:22:52 +0200 |
commit | 8823972649b0d3049c9c0d34b5f1d31160234fb4 (patch) | |
tree | e30b111bd9c2b5bfc0f47626e66887113207f422 | |
parent | 0b45b6e5de1ba4224ced67a9952e009d0f4139a0 (diff) |
indextargets: Check that cache could be built before using it
This caused a crash because the cache was a nullptr.
Closes: #829651
-rw-r--r-- | cmdline/apt-get.cc | 6 | ||||
-rw-r--r-- | test/integration/test-bug-829651 | 27 |
2 files changed, 30 insertions, 3 deletions
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 73db71f00..95d88e2ad 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -248,8 +248,9 @@ static bool DoIndexTargets(CommandLine &CmdL) { pkgCacheFile CacheFile; pkgSourceList *SrcList = CacheFile.GetSourceList(); + pkgCache *Cache = CacheFile.GetPkgCache(); - if (SrcList == NULL) + if (SrcList == nullptr || Cache == nullptr) return false; std::string const Format = _config->Find("APT::Get::IndexTargets::Format"); @@ -262,8 +263,7 @@ static bool DoIndexTargets(CommandLine &CmdL) if (ReleaseInfo) { AddOptions.insert(std::make_pair("TRUSTED", ((*S)->IsTrusted() ? "yes" : "no"))); - pkgCache &Cache = *CacheFile.GetPkgCache(); - pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(Cache, false); + pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(*Cache, false); if (RlsFile.end()) continue; #define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y())) diff --git a/test/integration/test-bug-829651 b/test/integration/test-bug-829651 new file mode 100644 index 000000000..976bb040c --- /dev/null +++ b/test/integration/test-bug-829651 @@ -0,0 +1,27 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +if [ "$(id -u)" = '0' ]; then + msgskip 'Tests for unreadable files do not work as root' + exit 0 +fi + +insertinstalledpackage 'foo' 'amd64' '1' +insertpackage 'unstable' 'foo' 'amd64' '2' + +setupaptarchive + + +testsuccess aptget indextargets + +aptget clean +chmod -r rootdir/var/lib/dpkg/status + +testfailureequal "E: Could not open file ${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status - open (13: Permission denied) +E: Problem opening ${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status +E: The package lists or status file could not be parsed or opened." aptget indextargets |