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

This commit is contained in:
hongjinghao 2024-03-25 16:58:50 +08:00
parent dff8919e50
commit 445d246981
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 b24c13e..a2bbedc 100644
--- a/lib/poptALL.c
+++ b/lib/poptALL.c
@@ -296,7 +296,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;
@@ -336,14 +336,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). */
@@ -355,4 +355,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 cf1f507..4281315 100644
--- a/tests/rpmgeneral.at
+++ b/tests/rpmgeneral.at
@@ -26,7 +26,6 @@ RPMTEST_CHECK([runroot rpm --version],[0],
])
RPMTEST_CLEANUP
-
# ------------------------------
AT_SETUP([rpmbuild --version])
AT_KEYWORDS([basic])
@@ -35,6 +34,15 @@ RPMTEST_CHECK([runroot rpmbuild --version],[0],
])
RPMTEST_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.18.2
Release: 4
Release: 5
Summary: RPM Package Manager
License: GPLv2+
URL: http://www.rpm.org/
@ -24,6 +24,8 @@ Patch6002: backport-Use-unsigned-integers-for-buildtime-too-for-Y2K38-sa.patch
Patch6003: backport-Fix-a-theoretical-use-of-uninitialized-struct-member.patch
Patch6004: backport-Fix-spec-parser-leaks-from-trans-f-file.patch
Patch6005: backport-Tip-toe-around-rpmfiFN-thin-ice-in-fsm.patch
Patch6006: backport-Fix-a-memleak-on-invalid-command-line-options.patch
Patch6007: backport-Let-eBPF-ELF-files-be-packaged-in-noarch-packages.patch
Patch9000: Add-digest-list-plugin.patch
Patch9001: Add-IMA-digest-list-support.patch
@ -322,6 +324,9 @@ make clean
%exclude %{_mandir}/man8/rpmspec.8.gz
%changelog
* Mon Mar 25 2024 hongjinghao<hongjinghao@huawei.com> - 4.18.2-5
- Fix memleak and let eBPF ELF files be packaged in noarch packages
* Thu Mar 21 2024 zhangguangzhi<zhangguangzhi3@huawei.com> - 4.18.2-4
- ima digest list support modsig