Blame SOURCES/0006-Fix-filtering-packages-by-advisory-RhBug-1770125.patch

462afb
From 594560870c416d0133b08a64e0632a53a6217f71 Mon Sep 17 00:00:00 2001
462afb
From: Marek Blaha <mblaha@redhat.com>
462afb
Date: Mon, 20 Jan 2020 09:58:03 +0100
462afb
Subject: [PATCH] Fix filtering packages by advisory (RhBug:1770125)
462afb
462afb
Currently the filter does not work well in situation when more versions
462afb
and architectures of advisory packages are available.
462afb
462afb
Let's have package gjs-1.56.2-6.fc30.x86_64
462afb
and two advisories related to gjs package:
462afb
FEDORA-2019-f4eb34cf4c
462afb
    gjs-1.56.2-1.fc30.src
462afb
    gjs-1.56.2-1.fc30.x86_64
462afb
FEDORA-2019-57b5902ed1
462afb
    gjs-1.56.2-6.fc30.src
462afb
    gjs-1.56.2-6.fc30.x86_64
462afb
462afb
In this case the FEDORA-2019-57b5902ed1 advisory is not matched for
462afb
gjs-1.56.2-6.fc30.x86_64 package (considering >= operator as in 'dnf
462afb
update --bugfix') because only the package of `src` architecture as been
462afb
checked. The checking of other versions/architectures was missing.
462afb
462afb
https://bugzilla.redhat.com/show_bug.cgi?id=1770125
462afb
---
462afb
 libdnf/sack/query.cpp | 63 +++++++++++++++----------------------------
462afb
 1 file changed, 22 insertions(+), 41 deletions(-)
462afb
462afb
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
462afb
index 6e9e4715f..122a50df6 100644
462afb
--- a/libdnf/sack/query.cpp
462afb
+++ b/libdnf/sack/query.cpp
462afb
@@ -518,9 +518,9 @@ advisoryPkgCompareSolvable(const AdvisoryPkg &first, const Solvable &s)
462afb
 {
462afb
     if (first.getName() != s.name)
462afb
         return first.getName() < s.name;
462afb
-    if (first.getEVR() != s.evr)
462afb
-        return first.getEVR() < s.evr;
462afb
-    return first.getArch() < s.arch;
462afb
+    if (first.getArch() != s.arch)
462afb
+        return first.getArch() < s.arch;
462afb
+    return first.getEVR() < s.evr;
462afb
 }
462afb
 
462afb
 static bool
462afb
@@ -1607,13 +1607,12 @@ Query::Impl::filterLocation(const Filter & f, Map *m)
462afb
 
462afb
 /**
462afb
 * @brief Reduce query to security filters. It reflect following compare types: HY_EQ, HY_GT, HY_LT.
462afb
-* In case HY_GT or HY_LT, it first find all advisory packages that EQ to packages in result.
462afb
-* Then it adds packages from Result to Map *m if Name and Arch is EQ, and EVR comparison is
462afb
-* according to one of selected compare type (HY_EQ, HY_GT, HY_LT).
462afb
 *
462afb
-* @param f p_f:...
462afb
-* @param m p_m:...
462afb
-* @param keyname p_keyname:...
462afb
+* @param f: Filter that should be applied on advisories
462afb
+* @param m: Map of query results complying the filter
462afb
+* @param keyname: how are the advisories matched. HY_PKG_ADVISORY, HY_PKG_ADVISORY_BUG,
462afb
+*                 HY_PKG_ADVISORY_CVE, HY_PKG_ADVISORY_TYPE  and HY_PKG_ADVISORY_SEVERITY
462afb
+*                 are supported
462afb
 */
462afb
 void
462afb
 Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
462afb
@@ -1668,7 +1667,6 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
462afb
     // convert nevras (from DnfAdvisoryPkg) to pool ids
462afb
     Id id = -1;
462afb
     int cmp_type = f.getCmpType();
462afb
-    bool cmpTypeGreaterOrLower = cmp_type & HY_GT || cmp_type & HY_LT;
462afb
     while (true) {
462afb
         if (pkgs.size() == 0)
462afb
             break;
462afb
@@ -1676,40 +1674,23 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
462afb
         if (id == -1)
462afb
             break;
462afb
         Solvable* s = pool_id2solvable(pool, id);
462afb
-        auto low = std::lower_bound(pkgs.begin(), pkgs.end(), *s, advisoryPkgCompareSolvable);
462afb
-        if (low != pkgs.end() && low->nevraEQ(s)) {
462afb
-            if (cmpTypeGreaterOrLower) {
462afb
-                pkgsSecondRun.push_back(*low);
462afb
-            } else {
462afb
+        if (cmp_type == HY_EQ) {
462afb
+            auto low = std::lower_bound(pkgs.begin(), pkgs.end(), *s, advisoryPkgCompareSolvable);
462afb
+            if (low != pkgs.end() && low->nevraEQ(s)) {
462afb
                 MAPSET(m, id);
462afb
             }
462afb
-        }
462afb
-    }
462afb
-    if (!cmpTypeGreaterOrLower) {
462afb
-        return;
462afb
-    }
462afb
-    std::sort(pkgsSecondRun.begin(), pkgsSecondRun.end(), advisoryPkgSort);
462afb
-    id = -1;
462afb
-    while (true) {
462afb
-        if (pkgsSecondRun.size() == 0)
462afb
-            break;
462afb
-        id = resultPset->next(id);
462afb
-        if (id == -1)
462afb
-            break;
462afb
-        Solvable* s = pool_id2solvable(pool, id);
462afb
-        auto low = std::lower_bound(pkgsSecondRun.begin(), pkgsSecondRun.end(), *s,
462afb
-                                    advisoryPkgCompareSolvableNameArch);
462afb
-        while (low != pkgsSecondRun.end() && low->getName() == s->name &&
462afb
-            low->getArch() == s->arch) {
462afb
-
462afb
-            int cmp = pool_evrcmp(pool, s->evr, low->getEVR(), EVRCMP_COMPARE);
462afb
-            if ((cmp > 0 && cmp_type & HY_GT) ||
462afb
-                (cmp < 0 && cmp_type & HY_LT) ||
462afb
-                (cmp == 0 && cmp_type & HY_EQ)) {
462afb
-                MAPSET(m, id);
462afb
-                break;
462afb
+        } else {
462afb
+            auto low = std::lower_bound(pkgs.begin(), pkgs.end(), *s, advisoryPkgCompareSolvableNameArch);
462afb
+            while (low != pkgs.end() && low->getName() == s->name && low->getArch() == s->arch) {
462afb
+                int cmp = pool_evrcmp(pool, s->evr, low->getEVR(), EVRCMP_COMPARE);
462afb
+                if ((cmp > 0 && cmp_type & HY_GT) ||
462afb
+                    (cmp < 0 && cmp_type & HY_LT) ||
462afb
+                    (cmp == 0 && cmp_type & HY_EQ)) {
462afb
+                    MAPSET(m, id);
462afb
+                    break;
462afb
+                }
462afb
+                ++low;
462afb
             }
462afb
-            ++low;
462afb
         }
462afb
     }
462afb
 }