summaryrefslogtreecommitdiff
path: root/apt-pkg/cachefile.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-11-20 00:54:07 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2015-11-20 00:54:07 +0100
commit6789e01e9370b3b7f65d52138c5657eaa712b4d1 (patch)
treecf0b9282cae981271918512f7af62da7dda4e64c /apt-pkg/cachefile.cc
parent520624d562e54e8e2c0191fae723e668e3ece6b4 (diff)
do not segfault in cache generation on mmap failure
Out of memory and similar circumstanzas could cause MMap::Map to fail and especially the mmap/malloc calls in it. With some additional checking we can avoid segfaults and similar in such situations – at least in theory as if this is a real out of memory everything we do to handle the error could just as well run into a memory problem as well… But at least in theory (if MMap::Map is made to fail always) we can deal with it so good that a user actually never sees a failure (as the cache it tries to load with it fails and is discarded, so that DynamicMMap takes over and a new one is build) instead of segfaulting. Closes: 803417
Diffstat (limited to 'apt-pkg/cachefile.cc')
-rw-r--r--apt-pkg/cachefile.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index aaa2436c5..39f1e72db 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -80,6 +80,8 @@ bool pkgCacheFile::BuildCaches(OpProgress *Progress, bool WithLock)
if (file.IsOpen() == false || file.Failed())
return false;
Map = new MMap(file, MMap::Public|MMap::ReadOnly);
+ if (unlikely(Map->validData() == false))
+ return false;
Cache = new pkgCache(Map);
return _error->PendingError() == false;
}