From 55585d0f93de1a0e60858e594b1b3b46f4a0831f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 22 Aug 2018 09:54:07 +0200 Subject: Don't use invalid iterator in Fallback-Of handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cppcheck reports: (error) Iterator 't' used after element has been erased. The loop is actually fashioned to deal with this (not in the most efficient way, but in simplest and speed isn't really a concern here) IF this codepath had a "break" at the end… so I added one. Note that the tests aren't failing before (and hopefully after) the change as the undefined behavior we encounter is too stable. Thanks: David Binderman for reporting --- apt-pkg/deb/debmetaindex.cc | 1 + test/integration/test-apt-acquire-additional-files | 21 +++++++++++++++++++-- .../test-sourceslist-target-plusminus-options | 4 ++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 6cbed85a7..9c7c70784 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1043,6 +1043,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ auto const tv = *t; mytargets.erase(t); mytargets.emplace_back(tv); + break; } if (Changed == false) break; diff --git a/test/integration/test-apt-acquire-additional-files b/test/integration/test-apt-acquire-additional-files index ff04b6346..928c703e1 100755 --- a/test/integration/test-apt-acquire-additional-files +++ b/test/integration/test-apt-acquire-additional-files @@ -214,9 +214,12 @@ testequal "$(readfile Contents-all)" aptget indextargets --format '$(FILENAME)' testsuccess cmp "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-all" 'aptarchive/dists/unstable/main/Contents-all' rm ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-all -rm -f rootdir/etc/apt/apt.conf.d/content-target.conf msgmsg "No Contents file" - +cat > rootdir/etc/apt/apt.conf.d/content-target-notdefault.conf < rootdir/etc/apt/sources.list testtargets 'duplications are okay' 'Packages' 'Translations' 'Contents' 'Contents2' + +# we can't check if it really reorders here +echo 'deb [target+=Contents2,Contents] http://example.org/debian stable rocks' > rootdir/etc/apt/sources.list +testtargets 'reordered fallback order' 'Packages' 'Translations' 'Contents' 'Contents2' -- cgit v1.2.3