diff --git a/backport-Add-check-after-malloc-allocation.patch b/backport-Add-check-after-malloc-allocation.patch new file mode 100644 index 0000000000000000000000000000000000000000..a29227a264040406eb0972223392f9b0b49b5741 --- /dev/null +++ b/backport-Add-check-after-malloc-allocation.patch @@ -0,0 +1,31 @@ +From 466bd9dd8b8836af34f29976a5b0b83950bbe8ed Mon Sep 17 00:00:00 2001 +From: Li kunyu +Date: Mon, 19 Dec 2022 15:20:42 +0800 +Subject: [PATCH] example_plugin: Add check after malloc allocation + +Reference:https://github.com/rpm-software-management/libdnf/commit/466bd9dd8b8836af34f29976a5b0b83950bbe8ed +Conflict:NA + +--- + plugins/example_plugin.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/plugins/example_plugin.c b/plugins/example_plugin.c +index 3f1b119f31..a12439bffd 100644 +--- a/plugins/example_plugin.c ++++ b/plugins/example_plugin.c +@@ -78,9 +78,11 @@ PluginHandle * pluginInitHandle(int version, PluginMode mode, DnfPluginInitData + break; + } + handle = malloc(sizeof(*handle)); +- handle->mode = mode; +- handle->context = pluginGetContext(initData); +- handle->outStream = outStream; ++ if (handle) { ++ handle->mode = mode; ++ handle->context = pluginGetContext(initData); ++ handle->outStream = outStream; ++ } + } while (0); + + fprintf(outStream, "%s: %s: exit =========================\n", info.name, __func__); diff --git a/backport-Fix-handling-transaction-id-in-resolveTransactionItemReason.patch b/backport-Fix-handling-transaction-id-in-resolveTransactionItemReason.patch new file mode 100644 index 0000000000000000000000000000000000000000..398d8fe902b34a10e54b612f04a309cc08f1dc96 --- /dev/null +++ b/backport-Fix-handling-transaction-id-in-resolveTransactionItemReason.patch @@ -0,0 +1,105 @@ +From 64b78c7dfbf85e9f93cd840ace4d51721814c489 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= +Date: Thu, 17 Feb 2022 18:18:16 +0100 +Subject: [PATCH 1/2] libdnf/transaction/RPMItem: Fix handling transaction id + in resolveTransactionItemReason + +The maxTransactionId argument was ignored, the method was always returning the +reason from the last transaction. This is the correct result for +maxTransactionId = -1. In a couple of places the method is called with +maxTransactionId = -2. Fixing this would mean nontrivial changes to the +logic which could potentially break something else, so I'm leaving this +behavior unchanged. + +For non-negative values of maxTransactionId (with which it's not being called +anywhere in dnf codebase), the commit adds a condition to SELECT only +transaction ids less than or equal to maxTransactionId. + += changelog = +msg: Fix handling transaction id in resolveTransactionItemReason +type: bugfix +resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2053014 +resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2010259 + +Conflict:NA +Reference:https://github.com/rpm-software-management/libdnf/pull/1447 +--- + libdnf/transaction/RPMItem.cpp | 21 ++++++++++++++++++--- + 1 file changed, 18 insertions(+), 3 deletions(-) + +diff --git a/libdnf/transaction/RPMItem.cpp b/libdnf/transaction/RPMItem.cpp +index 5f667ab967..ecce789d5c 100644 +--- a/libdnf/transaction/RPMItem.cpp ++++ b/libdnf/transaction/RPMItem.cpp +@@ -255,7 +255,11 @@ RPMItem::resolveTransactionItemReason(SQLite3Ptr conn, + const std::string &arch, + int64_t maxTransactionId) + { +- const char *sql = R"**( ++ // NOTE: All negative maxTransactionId values are treated the same. The ++ // method is called with maxTransactionId = -2 in a couple of places, the ++ // semantics here have been the same as with -1 for a long time. If it ++ // ain't broke... ++ std::string sql = R"**( + SELECT + ti.action as action, + ti.reason as reason +@@ -271,14 +275,25 @@ RPMItem::resolveTransactionItemReason(SQLite3Ptr conn, + AND ti.action not in (3, 5, 7, 10) + AND i.name = ? + AND i.arch = ? ++ )**"; ++ ++ if (maxTransactionId >= 0) { ++ sql.append(" AND ti.trans_id <= ?"); ++ } ++ ++ sql.append(R"**( + ORDER BY + ti.trans_id DESC + LIMIT 1 +- )**"; ++ )**"); + + if (arch != "") { + SQLite3::Query query(*conn, sql); +- query.bindv(name, arch); ++ if (maxTransactionId >= 0) { ++ query.bindv(name, arch, maxTransactionId); ++ } else { ++ query.bindv(name, arch); ++ } + + if (query.step() == SQLite3::Statement::StepResult::ROW) { + auto action = static_cast< TransactionItemAction >(query.get< int64_t >("action")); + +From 9f065a778cdba1c27ce252944e21bcc6300e1b24 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= +Date: Thu, 17 Feb 2022 18:30:14 +0100 +Subject: [PATCH 2/2] libdnf/transaction/TransactionItem: Set short action for + Reason Change + +Sets the "short" (one letter) representation of the Reason Change action +to "C". + +This was likely not ever used before as the only way to create a +transaction with a reason change and something else is rolling back +multiple transactions, which was broken. +--- + libdnf/transaction/TransactionItem.cpp | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/libdnf/transaction/TransactionItem.cpp b/libdnf/transaction/TransactionItem.cpp +index 3b43d1f128..4358038eb0 100644 +--- a/libdnf/transaction/TransactionItem.cpp ++++ b/libdnf/transaction/TransactionItem.cpp +@@ -51,8 +51,7 @@ static const std::map< TransactionItemAction, std::string > transactionItemActio + {TransactionItemAction::REMOVE, "E"}, + {TransactionItemAction::REINSTALL, "R"}, + {TransactionItemAction::REINSTALLED, "R"}, +- // TODO: replace "?" with something better +- {TransactionItemAction::REASON_CHANGE, "?"}, ++ {TransactionItemAction::REASON_CHANGE, "C"}, + }; + + /* diff --git a/libdnf.spec b/libdnf.spec index e38e959a38c88d60ca6deb091eab6543a14efc42..8b9d23e5e7fea19c4c70a648f0b15d8008dcede0 100644 --- a/libdnf.spec +++ b/libdnf.spec @@ -18,7 +18,7 @@ Name: libdnf Version: 0.65.0 -Release: 5 +Release: 6 Summary: Library providing simplified C and Python API to libsolv License: LGPLv2+ URL: https://github.com/rpm-software-management/libdnf @@ -30,7 +30,9 @@ Patch6002: Fix-listing-a-repository-without-cpeid.patch %ifarch loongarch64 Patch6003: 0001-libdnf-0.65.0-add-loongarch-support.patch %endif -Patch6004: backport-query-py-ensure-reldep-is-from-the-same-sack.patch +Patch6004: backport-Fix-handling-transaction-id-in-resolveTransactionItemReason.patch +Patch6005: backport-query-py-ensure-reldep-is-from-the-same-sack.patch +Patch6006: backport-Add-check-after-malloc-allocation.patch BuildRequires: cmake gcc gcc-c++ libsolv-devel >= %{libsolv_version} gettext BuildRequires: pkgconfig(librepo) >= %{librepo_version} pkgconfig(check) @@ -126,6 +128,11 @@ popd %{python3_sitearch}/hawkey/ %changelog +* Wed May 24 2023 chenhaixing - 0.65.0-6 +- CVE:NA +- SUG:NA +- DESC:libdnf:backport patch to fix undo error and add check after malloc allocation + * Mon Feb 13 2023 zhangrui - 0.65.0-5 - DESC:backport patch Ensure reldep is from the same sack