summaryrefslogtreecommitdiff
path: root/apt-private/private-show.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 /apt-private/private-show.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 'apt-private/private-show.cc')
-rw-r--r--apt-private/private-show.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc
index d28387ba9..03229476e 100644
--- a/apt-private/private-show.cc
+++ b/apt-private/private-show.cc
@@ -258,6 +258,8 @@ bool ShowPackage(CommandLine &CmdL) /*{{{*/
CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
APT::CacheSetHelper::VerSelector const select = _config->FindB("APT::Cache::AllVersions", true) ?
APT::CacheSetHelper::ALL : APT::CacheSetHelper::CANDIDATE;
+ if (select == APT::CacheSetHelper::CANDIDATE && CacheFile.GetDepCache() == nullptr)
+ return false;
APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper);
int const ShowVersion = _config->FindI("APT::Cache::Show::Version", 1);
for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver)
@@ -356,10 +358,14 @@ bool ShowSrcPackage(CommandLine &CmdL) /*{{{*/
bool Policy(CommandLine &CmdL)
{
pkgCacheFile CacheFile;
- pkgCache *Cache = CacheFile.GetPkgCache();
- pkgPolicy *Plcy = CacheFile.GetPolicy();
- pkgSourceList *SrcList = CacheFile.GetSourceList();
- if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL))
+ pkgSourceList const * const SrcList = CacheFile.GetSourceList();
+ if (unlikely(SrcList == nullptr))
+ return false;
+ pkgCache * const Cache = CacheFile.GetPkgCache();
+ if (unlikely(Cache == nullptr))
+ return false;
+ pkgPolicy * const Plcy = CacheFile.GetPolicy();
+ if (unlikely(Plcy == nullptr))
return false;
// Print out all of the package files