Blame SOURCES/0001-advisory-upgrade-filter-out-advPkgs-with-different-a.patch

ec6979
From c17e59faf6075e7ddb803f6393e86653afd6b16d Mon Sep 17 00:00:00 2001
ec6979
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
ec6979
Date: Mon, 30 May 2022 08:59:41 +0200
ec6979
Subject: [PATCH] advisory upgrade: filter out advPkgs with different arch
ec6979
ec6979
This prevents a situation in security upgrades where libsolv cannot
ec6979
upgrade dependent pkgs because we ask for an upgrade of different arch:
ec6979
ec6979
We can get the following testcase if libdnf has filtered out
ec6979
json-c-2-2.el8.x86_64@rhel-8-for-x86_64-baseos-rpms
ec6979
(because there is an advisory for already installed json-c-1-1.el8.x86_64) but
ec6979
json-c-2-2.el8.i686@rhel-8-for-x86_64-baseos-rpms is not filtered out because
ec6979
it has different architecture. The resulting transaction doesn't work.
ec6979
ec6979
```
ec6979
repo @System -99.-1000 testtags <inline>
ec6979
#>=Pkg: bind-libs-lite 1 1.el8 x86_64
ec6979
#>=Pkg: json-c 1 1.el8 x86_64
ec6979
ec6979
repo rhel-8-for-x86_64-baseos-rpms -99.-1000 testtags <inline>
ec6979
#>=Pkg: json-c 2 2.el8 x86_64
ec6979
#>=Prv: libjson-c.so.4()(64bit)
ec6979
#>
ec6979
#>=Pkg: json-c 2 2.el8 i686
ec6979
#>=Prv: libjson-c.so.4()
ec6979
#>
ec6979
#>=Pkg: bind-libs-lite 2 2.el8 x86_64
ec6979
#>=Req: libjson-c.so.4()(64bit)
ec6979
system x86_64 rpm @System
ec6979
job update oneof json-c-1-1.el8.x86_64@@System json-c-2-2.el8.i686@rhel-8-for-x86_64-baseos-rpms bind-libs-lite-2-2.el8.x86_64@rhel-8-for-x86_64-baseos-rpms [forcebest,targeted,setevr,setarch]
ec6979
result transaction,problems <inline>
ec6979
#>problem f06d81a4 info package bind-libs-lite-2-2.el8.x86_64 requires libjson-c.so.4()(64bit), but none of the providers can be installed
ec6979
#>problem f06d81a4 solution 96f9031b allow bind-libs-lite-1-1.el8.x86_64@@System
ec6979
#>problem f06d81a4 solution c8daf94f allow json-c-2-2.el8.x86_64@rhel-8-for-x86_64-baseos-rpms
ec6979
#>upgrade bind-libs-lite-1-1.el8.x86_64@@System bind-libs-lite-2-2.el8.x86_64@rhel-8-for-x86_64-baseos-rpms
ec6979
#>upgrade json-c-1-1.el8.x86_64@@System json-c-2-2.el8.x86_64@rhel-8-for-x86_64-baseos-rpms```
ec6979
```
ec6979
ec6979
= changelog =
ec6979
msg: Filter out advisory pkgs with different arch during advisory upgrade, fixes possible problems in dependency resulution.
ec6979
type: bugfix
ec6979
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2088149
ec6979
---
ec6979
 libdnf/sack/query.cpp | 25 +++++++++++++++++++------
ec6979
 1 file changed, 19 insertions(+), 6 deletions(-)
ec6979
ec6979
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
ec6979
index ac2736b5..03d39659 100644
ec6979
--- a/libdnf/sack/query.cpp
ec6979
+++ b/libdnf/sack/query.cpp
ec6979
@@ -1877,12 +1877,6 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
ec6979
         std::vector<Solvable *> candidates;
ec6979
         std::vector<Solvable *> installed_solvables;
ec6979
 
ec6979
-        Id id = -1;
ec6979
-        while ((id = resultPset->next(id)) != -1) {
ec6979
-            candidates.push_back(pool_id2solvable(pool, id));
ec6979
-        }
ec6979
-        NameArchEVRComparator cmp_key(pool);
ec6979
-
ec6979
         if (cmp_type & HY_UPGRADE) {
ec6979
             Query installed(sack, ExcludeFlags::IGNORE_EXCLUDES);
ec6979
             installed.installed();
ec6979
@@ -1893,6 +1887,18 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
ec6979
                 installed_solvables.push_back(pool_id2solvable(pool, installed_id));
ec6979
             }
ec6979
             std::sort(installed_solvables.begin(), installed_solvables.end(), NameArchSolvableComparator);
ec6979
+            Id id = -1;
ec6979
+            while ((id = resultPset->next(id)) != -1) {
ec6979
+                Solvable * s = pool_id2solvable(pool, id);
ec6979
+                // When doing HY_UPGRADE consider only candidate pkgs that have matching Name and Arch
ec6979
+                // with some already installed pkg (in other words: some other version of the pkg is already installed).
ec6979
+                // Otherwise a pkg with different Arch than installed can end up in upgrade set which is wrong.
ec6979
+                // It can result in dependency issues, reported as: RhBug:2088149.
ec6979
+                auto low = std::lower_bound(installed_solvables.begin(), installed_solvables.end(), s, NameArchSolvableComparator);
ec6979
+                if (low != installed_solvables.end() && s->name == (*low)->name && s->arch == (*low)->arch) {
ec6979
+                    candidates.push_back(s);
ec6979
+                }
ec6979
+            }
ec6979
 
ec6979
             // Apply security filters only to packages with lower priority - to unify behaviour upgrade
ec6979
             // and upgrade-minimal
ec6979
@@ -1915,7 +1921,14 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
ec6979
                 }
ec6979
             }
ec6979
             std::swap(candidates, priority_candidates);
ec6979
+        } else {
ec6979
+            Id id = -1;
ec6979
+            while ((id = resultPset->next(id)) != -1) {
ec6979
+                candidates.push_back(pool_id2solvable(pool, id));
ec6979
+            }
ec6979
         }
ec6979
+
ec6979
+        NameArchEVRComparator cmp_key(pool);
ec6979
         std::sort(candidates.begin(), candidates.end(), cmp_key);
ec6979
         for (auto & advisoryPkg : pkgs) {
ec6979
             if (cmp_type & HY_UPGRADE) {
ec6979
-- 
ec6979
2.36.1
ec6979