代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。