summaryrefslogtreecommitdiff
path: root/cmdline/apt-mark.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-05-20 09:37:24 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2016-05-20 09:37:24 +0200
commitfdf9eef4d96a18d0167708499c993e1174251e88 (patch)
tree049dd9a8405ac4a3a489a02475ad57235e1538f5 /cmdline/apt-mark.cc
parent91be4122fb4dba065c19ea3f292b1945a94b5d99 (diff)
fail instead of segfault on unreadable config files
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
Diffstat (limited to 'cmdline/apt-mark.cc')
-rw-r--r--cmdline/apt-mark.cc27
1 files changed, 12 insertions, 15 deletions
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<string> 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;