From 5d07bad6105eb1b7c158c502fe89803e120be064 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 6 Feb 2019 15:01:22 +0100 Subject: Fix crashes in apt search, cache file When BuildDepCaches() is called before BuildCaches() we end up with dereferencing a null pointer cache in the depcache constructor. Furthermore, in private-search, we check that Cache == NULL, but only after constructing the policy and records, which does not work reliably, because the records construction accesses the cache as well. LP: #1815187 Test-Case: ./build/bin/apt search -o RootDir=/dev/null foo --- apt-pkg/cachefile.cc | 2 ++ apt-private/private-search.cc | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index 0fd40106f..96bcdc097 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -140,6 +140,8 @@ bool pkgCacheFile::BuildPolicy(OpProgress * /*Progress*/) /* */ bool pkgCacheFile::BuildDepCache(OpProgress *Progress) { + if (BuildCaches(Progress, false) == false) + return false; if (DCache != NULL) return true; diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc index ecd5d7fad..e218bf76c 100644 --- a/apt-private/private-search.cc +++ b/apt-private/private-search.cc @@ -31,9 +31,13 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/ { pkgCacheFile CacheFile; pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) + return false; + pkgDepCache::Policy *Plcy = CacheFile.GetPolicy(); pkgRecords records(CacheFile); - if (unlikely(Cache == NULL || Plcy == NULL)) + + if (unlikely(Plcy == NULL)) return false; const char **patterns; -- cgit v1.2.3