Fix memleak and let eBPF ELF files be packaged in noarch packages

(cherry picked from commit 7be7f1b9c564d90a4d60cd4500677a60b307e250)
This commit is contained in:
hongjinghao 2024-03-25 11:31:12 +08:00 committed by openeuler-sync-bot
parent f2618d7172
commit 26a8750ad7
3 changed files with 135 additions and 1 deletions

View File

@ -0,0 +1,85 @@
From 1825dbf8244b129665a69481c4537a57b9e03a8f Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Wed, 21 Feb 2024 16:07:05 +0200
Subject: [PATCH] Fix a memleak on invalid command line options
The OS will clean it up yes, but in the meanwhile ASAN (when enabled)
blew up on your face and scared you silly. Use the opportunity to add a
test for a test on invalid option.
---
lib/poptALL.c | 11 ++++++++---
tests/rpmgeneral.at | 10 +++++++++-
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/lib/poptALL.c b/lib/poptALL.c
index 0fa1c40..3c4c096 100644
--- a/lib/poptALL.c
+++ b/lib/poptALL.c
@@ -294,7 +294,7 @@ rpmcliFini(poptContext optCon)
poptContext
rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
{
- poptContext optCon;
+ poptContext optCon = NULL;
int rc;
const char *ctx, *execPath;
@@ -332,14 +332,14 @@ rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
while ((rc = poptGetNextOpt(optCon)) > 0) {
fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
xgetprogname(), rc);
- exit(EXIT_FAILURE);
+ goto err;
}
if (rc < -1) {
fprintf(stderr, "%s: %s: %s\n", xgetprogname(),
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
poptStrerror(rc));
- exit(EXIT_FAILURE);
+ goto err;
}
/* Read rpm configuration (if not already read). */
@@ -351,4 +351,9 @@ rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
}
return optCon;
+
+err:
+ poptFreeContext(optCon);
+ exit(EXIT_FAILURE);
+ return NULL; /* not reached */
}
diff --git a/tests/rpmgeneral.at b/tests/rpmgeneral.at
index 5cbfc23..6d85ace 100644
--- a/tests/rpmgeneral.at
+++ b/tests/rpmgeneral.at
@@ -26,7 +26,6 @@ AT_CHECK([runroot rpm --version],[0],
])
AT_CLEANUP
-
# ------------------------------
AT_SETUP([rpmbuild --version])
AT_KEYWORDS([basic])
@@ -35,6 +34,15 @@ AT_CHECK([runroot rpmbuild --version],[0],
])
AT_CLEANUP
+AT_SETUP([rpm invalid option])
+AT_KEYWORDS([basic])
+AT_CHECK([runroot rpm --badopt],
+[1],
+[],
+[rpm: --badopt: unknown option
+])
+AT_CLEANUP
+
# Check that libtool versioning matches expectations, it's easy to screw up.
AT_SETUP([rpm library version])
AT_KEYWORDS([basic])
--
2.33.0

View File

@ -0,0 +1,44 @@
From 5ece87a250880b08ccecfc5b34986347d8cca843 Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Thu, 8 Feb 2024 09:44:51 +0200
Subject: [PATCH] Let eBPF ELF files be packaged in noarch packages
eBPF ELF represents a virtual machine where our file colors make no
sense at all. Filter out the color from these files to avoid a
"Arch dependent binaries in noarch package" error from them in noarch
packages.
We don't want to pull in clang to the check images just because of
this, so add a pre-built binary for the check and a simple way to
reproduce from the test-spec.
Fixes: #2875
Reference:https://github.com/rpm-software-management/rpm/commit/5ece87a250880b08ccecfc5b34986347d8cca843
Conflict:Deleted binary files and test code because it would add clang
Requires.
---
build/rpmfc.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/build/rpmfc.c b/build/rpmfc.c
index 07171fa..6d40a19 100644
--- a/build/rpmfc.c
+++ b/build/rpmfc.c
@@ -1151,6 +1151,13 @@ static uint32_t getElfColor(const char *fn)
color = RPMFC_ELF32;
break;
}
+
+ /* Exceptions to coloring */
+ switch (ehdr.e_machine) {
+ case EM_BPF:
+ color = 0;
+ break;
+ }
}
if (elf)
elf_end(elf);
--
2.33.0

View File

@ -1,6 +1,6 @@
Name: rpm
Version: 4.17.0
Release: 34
Release: 35
Summary: RPM Package Manager
License: GPLv2+
URL: http://www.rpm.org/
@ -118,6 +118,8 @@ Patch6079: backport-Use-unsigned-integers-for-buildtime-too-for-Y2K38-sa.patch
Patch6080: backport-Fix-a-theoretical-use-of-uninitialized-struct-member.patch
Patch6081: backport-Fix-spec-parser-leaks-from-trans-f-file.patch
Patch6082: backport-Tip-toe-around-rpmfiFN-thin-ice-in-fsm.patch
Patch6083: backport-Fix-a-memleak-on-invalid-command-line-options.patch
Patch6084: backport-Let-eBPF-ELF-files-be-packaged-in-noarch-packages.patch
BuildRequires: gcc autoconf automake libtool make gawk popt-devel openssl-devel readline-devel
BuildRequires: zlib-devel zstd-devel >= 1.3.8 xz-devel bzip2-devel libarchive-devel ima-evm-utils-devel
@ -408,6 +410,9 @@ make check || (cat tests/rpmtests.log; exit 0)
%{_mandir}/man1/gendiff.1*
%changelog
* Mon Mar 25 2024 hongjinghao<hongjinghao@huawei.com> - 4.17.0-35
- Fix memleak and let eBPF ELF files be packaged in noarch packages
* Wed Mar 13 2024 gengqihu<gengqihu2@h-partners.com> - 4.17.0-34
- Backport some patches from upstream