From fdf9eef4d96a18d0167708499c993e1174251e88 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 May 2016 09:37:24 +0200 Subject: fail instead of segfault on unreadable config files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The report mentions "apt list --upgradable", but there are others which have inconsistent behavior ranging from segfaulting to doing something with the partial (and hence incomplete) data. We had a recent report about sources.list (#818628), this one mentions prefences, the obvious next step is conf files… so the testcase is adapted to check for all three in file and directory versions and run a bunch of commands each time which should all have more or less the same behavior in such a case (aka error out). Closes: 824503 --- cmdline/apt-mark.cc | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index 8b615a83b..4e86edc77 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -48,9 +48,8 @@ using namespace std; static bool DoAuto(CommandLine &CmdL) { pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - pkgDepCache *DepCache = CacheFile.GetDepCache(); - if (unlikely(Cache == NULL || DepCache == NULL)) + pkgDepCache * const DepCache = CacheFile.GetDepCache(); + if (unlikely(DepCache == nullptr)) return false; APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1); @@ -95,9 +94,8 @@ static bool DoAuto(CommandLine &CmdL) static bool DoMarkAuto(CommandLine &CmdL) { pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - pkgDepCache *DepCache = CacheFile.GetDepCache(); - if (unlikely(Cache == NULL || DepCache == NULL)) + pkgDepCache * const DepCache = CacheFile.GetDepCache(); + if (unlikely(DepCache == nullptr)) return false; APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1); @@ -132,9 +130,8 @@ static bool DoMarkAuto(CommandLine &CmdL) static bool ShowAuto(CommandLine &CmdL) { pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - pkgDepCache *DepCache = CacheFile.GetDepCache(); - if (unlikely(Cache == NULL || DepCache == NULL)) + pkgDepCache * const DepCache = CacheFile.GetDepCache(); + if (unlikely(DepCache == nullptr)) return false; std::vector packages; @@ -143,8 +140,8 @@ static bool ShowAuto(CommandLine &CmdL) if (CmdL.FileList[1] == 0) { - packages.reserve(Cache->HeaderP->PackageCount / 3); - for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P) + packages.reserve(DepCache->Head().PackageCount / 3); + for (pkgCache::PkgIterator P = DepCache->PkgBegin(); P.end() == false; ++P) if (P->CurrentVer != 0 && (((*DepCache)[P].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto) == ShowAuto) packages.push_back(P.FullName(true)); @@ -172,8 +169,8 @@ static bool ShowAuto(CommandLine &CmdL) static bool DoSelection(CommandLine &CmdL) { pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) + pkgCache * const Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == nullptr)) return false; APT::VersionVector pkgset = APT::VersionVector::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::INSTCAND); @@ -238,8 +235,8 @@ static bool DoSelection(CommandLine &CmdL) static bool ShowSelection(CommandLine &CmdL) /*{{{*/ { pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) + pkgCache * const Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == nullptr)) return false; pkgCache::State::PkgSelectedState selector; -- cgit v1.2.3