From a8cb287cab8980823dd6dc9dca8d70b2bd008009 Mon Sep 17 00:00:00 2001 From: xujing Date: Sat, 5 Nov 2022 17:03:30 +0800 Subject: [PATCH] rpm: Rework and clarify database backend detection logic --- ...ausing-segfault-on-database-autodete.patch | 28 +++++ ...ify-database-backend-detection-logic.patch | 109 ++++++++++++++++++ rpm.spec | 7 +- 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-regression-causing-segfault-on-database-autodete.patch create mode 100644 backport-Rework-and-clarify-database-backend-detection-logic.patch diff --git a/backport-Fix-regression-causing-segfault-on-database-autodete.patch b/backport-Fix-regression-causing-segfault-on-database-autodete.patch new file mode 100644 index 0000000..0aed034 --- /dev/null +++ b/backport-Fix-regression-causing-segfault-on-database-autodete.patch @@ -0,0 +1,28 @@ +From 853c48ba6468ce1a516621a2fa6d1fc51e4f7410 Mon Sep 17 00:00:00 2001 +From: Panu Matilainen +Date: Thu, 2 Apr 2020 09:14:36 +0300 +Subject: [PATCH] Fix regression causing segfault on database autodetection + +If configuration points to non-existent backend, tryBackend() will +segfault on the first call. Duh. Regression introduced in commit +3eb0eed3806b41efdf86f0433d0b5d7d6c953561. +--- + lib/backend/dbi.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/backend/dbi.c b/lib/backend/dbi.c +index b51fc7ba3..94823b14c 100644 +--- a/lib/backend/dbi.c ++++ b/lib/backend/dbi.c +@@ -52,7 +52,7 @@ dbiIndex dbiNew(rpmdb rdb, rpmDbiTagVal rpmtag) + static int tryBackend(const char *dbhome, const struct rpmdbOps_s *be) + { + int rc = 0; +- if (be->path) { ++ if (be && be->path) { + char *path = rstrscat(NULL, dbhome, "/", be->path, NULL); + rc = (access(path, F_OK) == 0); + free(path); +-- +2.27.0 + diff --git a/backport-Rework-and-clarify-database-backend-detection-logic.patch b/backport-Rework-and-clarify-database-backend-detection-logic.patch new file mode 100644 index 0000000..09ae20f --- /dev/null +++ b/backport-Rework-and-clarify-database-backend-detection-logic.patch @@ -0,0 +1,109 @@ +From 3eb0eed3806b41efdf86f0433d0b5d7d6c953561 Mon Sep 17 00:00:00 2001 +From: Panu Matilainen +Date: Wed, 11 Mar 2020 15:12:23 +0200 +Subject: [PATCH] Rework and clarify database backend detection logic + +Try the configured backend first, and only if that fails try autodetection. +The former logic did not anticipate multiple backends handling same +files and gets mightily confused when both bdb and bdb-ro are enabled, +causing half the test-suite failing in "make check". + +Also emit a different message when database rebuild is in progress, +the old message is quite confusing in that case. + +Loosely based on a similar patch by Michael Schroeder. +--- + lib/backend/dbi.c | 61 +++++++++++++++++++++++++++++++++-------------- + 1 file changed, 43 insertions(+), 18 deletions(-) + +diff --git a/lib/backend/dbi.c b/lib/backend/dbi.c +index 784144088..ddd52bc10 100644 +--- a/lib/backend/dbi.c ++++ b/lib/backend/dbi.c +@@ -51,40 +51,65 @@ dbiIndex dbiNew(rpmdb rdb, rpmDbiTagVal rpmtag) + return dbi; + } + ++/* Test whether there's a database for this backend, return true/false */ ++static int tryBackend(const char *dbhome, const struct rpmdbOps_s *be) ++{ ++ int rc = 0; ++ if (be->path) { ++ char *path = rstrscat(NULL, dbhome, "/", be->path, NULL); ++ rc = (access(path, F_OK) == 0); ++ free(path); ++ } ++ return rc; ++} ++ + static void + dbDetectBackend(rpmdb rdb) + { + const char *dbhome = rpmdbHome(rdb); + char *db_backend = rpmExpand("%{?_db_backend}", NULL); +- char *path = NULL; + const struct rpmdbOps_s **ops; ++ const struct rpmdbOps_s *cfg = NULL; ++ const struct rpmdbOps_s *ondisk = NULL; + ++ /* Find configured backend */ + for (ops = backends; ops && *ops; ops++) { + if (rstreq(db_backend, (*ops)->name)) { +- rdb->db_ops = *ops; ++ cfg = *ops; + break; + } + } + +- for (ops = backends; ops && *ops; ops++) { +- int stop = 0; +- if ((*ops)->path == NULL) +- continue; +- +- path = rstrscat(NULL, dbhome, "/", (*ops)->path, NULL); +- if (access(path, F_OK) == 0 && rdb->db_ops != *ops) { +- rpmlog(RPMLOG_WARNING, +- _("Found %s %s database while attempting %s backend: " +- "using %s backend.\n"), +- (*ops)->name, (*ops)->path, db_backend, (*ops)->name); +- rdb->db_ops = *ops; +- stop = 1; ++ /* If configured database doesn't exist, try autodetection */ ++ if (!tryBackend(dbhome, cfg)) { ++ for (ops = backends; ops && *ops; ops++) { ++ if (tryBackend(dbhome, *ops)) { ++ ondisk = *ops; ++ break; ++ } ++ } ++ ++ /* On-disk database differs from configuration */ ++ if (ondisk && ondisk != cfg) { ++ if (rdb->db_flags & RPMDB_FLAG_REBUILD) { ++ rpmlog(RPMLOG_WARNING, ++ _("Converting database from %s to %s backend\n"), ++ ondisk->name, cfg->name); ++ } else { ++ rpmlog(RPMLOG_WARNING, ++ _("Found %s %s database while attempting %s backend: " ++ "using %s backend.\n"), ++ ondisk->name, ondisk->path, db_backend, ondisk->name); ++ } ++ rdb->db_ops = ondisk; + } +- free(path); +- if (stop) +- break; + } + ++ /* Newly created database, use configured backend */ ++ if (rdb->db_ops == NULL && cfg) ++ rdb->db_ops = cfg; ++ ++ /* If all else fails... */ + if (rdb->db_ops == NULL) { + rdb->db_ops = &dummydb_dbops; + rpmlog(RPMLOG_WARNING, "using dummy database, installs not possible\n"); +-- +2.27.0 + diff --git a/rpm.spec b/rpm.spec index 8e292b6..d6de435 100644 --- a/rpm.spec +++ b/rpm.spec @@ -1,6 +1,6 @@ Name: rpm Version: 4.15.1 -Release: 28 +Release: 29 Summary: RPM Package Manager License: GPLv2+ URL: http://www.rpm.org/ @@ -80,6 +80,8 @@ Patch67: backport-Bury-rpmio-FD-use-to-fsmUnpack.patch Patch68: backport-Move-file-metadata-setting-back-to-unpack-stage.patch Patch69: backport-Return-descriptor-of-created-file-from-fsmMkfile.patch Patch70: backport-CVE-2021-35938.patch +Patch71: backport-Rework-and-clarify-database-backend-detection-logic.patch +Patch72: backport-Fix-regression-causing-segfault-on-database-autodete.patch BuildRequires: gcc autoconf automake libtool make gawk popt-devel openssl-devel readline-devel libdb-devel BuildRequires: zlib-devel libzstd-devel xz-devel bzip2-devel libarchive-devel ima-evm-utils-devel @@ -363,6 +365,9 @@ make check || (cat tests/rpmtests.log; exit 0) %{_mandir}/man1/gendiff.1* %changelog +* Sat Nov 05 2022 xujing - 4.15.1-29 +- Rework and clarify database backend detection logic + * Wed Sep 07 2022 Hongxun Ren - 4.15.1-28 - fix CVE-2021-35937 CVE-2021-35938 CVE-2021-35939 -- Gitee