From cafebee579f6a9399fbfcc86e2c89a479aee465e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 27 Jan 2020 13:23:53 +0100 Subject: NewGroup: Create GrpIterator after allocation (fix segfault) NewGroup created a GrpIterator and then called WriteStringInMap() which might remap the cache, causing the iterator to go invalid. Avoid this simply by creating the iterator later on. --- apt-pkg/pkgcachegen.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 8e0301151..dfac0ae1c 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -557,10 +557,11 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, StringView Name) if (unlikely(Group == 0)) return false; - Grp = pkgCache::GrpIterator(Cache, Cache.GrpP + Group); map_stringitem_t const idxName = WriteStringInMap(Name); if (unlikely(idxName == 0)) return false; + + Grp = pkgCache::GrpIterator(Cache, Cache.GrpP + Group); Grp->Name = idxName; // Insert it into the hash table -- cgit v1.2.3