update to 1.19

This commit is contained in:
dillon_chen 2022-11-18 17:18:23 +08:00
parent 1c33002d26
commit 7f62c46441
5 changed files with 6 additions and 130 deletions

View File

@ -1,38 +0,0 @@
From cd32d1c7da8265a06491d72190c649496ae2f489 Mon Sep 17 00:00:00 2001
From: Tobias Stoeckmann <tobias@stoeckmann.org>
Date: Sun, 16 Aug 2020 20:39:20 +0200
Subject: [PATCH] Consider POPT_CONTEXT_KEEP_FIRST during reset.
If context is created with POPT_CONTEXT_KEEP_FIRST flag, then the
first argv entry is parsed as well (argv[0] is normally the program
name).
Calling poptResetContext should reset the context exactly back into
the state in wich it was after poptGetContext.
Unfortunately the "next" value is always set to 1, i.e. pointing
towards argv[1]. Consider POPT_CONTEXT_KEEP_FIRST. If it is set,
point to argv[0] just like poptGetContext does.
---
src/popt.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/popt.c b/src/popt.c
index c08b3c9..b7d9478 100644
--- a/src/popt.c
+++ b/src/popt.c
@@ -210,7 +210,10 @@ void poptResetContext(poptContext con)
con->os->currAlias = NULL;
con->os->nextCharArg = NULL;
con->os->nextArg = _free(con->os->nextArg);
- con->os->next = 1; /* skip argv[0] */
+ if (!(con->flags & POPT_CONTEXT_KEEP_FIRST))
+ con->os->next = 1; /* skip argv[0] */
+ else
+ con->os->next = 0;
con->numLeftovers = 0;
con->nextLeftover = 0;
--
2.27.0

View File

@ -1,87 +0,0 @@
From 7219e1ddc1e8606dda18c1105df0d45d8e8e0e09 Mon Sep 17 00:00:00 2001
From: Richard Levitte <richard@levitte.org>
Date: Mon, 29 Jun 2020 11:56:00 -0400
Subject: [PATCH] Fix incorrect handling of leftovers with poptStuffArgs
If poptStuffArgs() is used twice with the same context, it will invariably
cause memory corruption and possibly memory leaks or a crash.
Change the allocation of leftOvers so it adapts to the input on the fly
instead of trying to pre-allocate it in one go.
---
src/popt.c | 24 ++++++++++++++++++++++--
src/poptint.h | 1 +
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/popt.c b/src/popt.c
index b7d9478..ab7b54f 100644
--- a/src/popt.c
+++ b/src/popt.c
@@ -168,6 +168,7 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv,
con->os->next = 1; /* skip argv[0] */
con->leftovers = calloc( (size_t)(argc + 1), sizeof(*con->leftovers) );
+ con->allocLeftovers = argc + 1;
con->options = options;
con->aliases = NULL;
con->numAliases = 0;
@@ -1272,8 +1273,21 @@ int poptGetNextOpt(poptContext con)
con->os->nextArg = xstrdup(origOptString);
return 0;
}
- if (con->leftovers != NULL) /* XXX can't happen */
- con->leftovers[con->numLeftovers++] = origOptString;
+ if (con->leftovers != NULL) { /* XXX can't happen */
+ /* One might think we can never overflow the leftovers
+ array. Actually, that's true, as long as you don't
+ use poptStuffArgs()... */
+ if ((con->numLeftovers + 1) >= (con->allocLeftovers)) {
+ con->allocLeftovers += 10;
+ con->leftovers =
+ realloc(con->leftovers,
+ sizeof(*con->leftovers) * con->allocLeftovers);
+ }
+ con->leftovers[con->numLeftovers++]
+ = xstrdup(origOptString); /* so a free of a stuffed
+ argv doesn't give us a
+ dangling pointer */
+ }
continue;
}
@@ -1521,6 +1535,8 @@ poptItem poptFreeItems(poptItem items, int nitems)
poptContext poptFreeContext(poptContext con)
{
+ int i;
+
if (con == NULL) return con;
poptResetContext(con);
@@ -1530,7 +1546,11 @@ poptContext poptFreeContext(poptContext con)
con->execs = poptFreeItems(con->execs, con->numExecs);
con->numExecs = 0;
+ for (i = 0; i < con->numLeftovers; i++) {
+ con->leftovers[i] = _free(&con->leftovers[i]);
+ }
con->leftovers = _free(con->leftovers);
+
con->finalArgv = _free(con->finalArgv);
con->appName = _free(con->appName);
con->otherHelp = _free(con->otherHelp);
diff --git a/src/poptint.h b/src/poptint.h
index b64e123..d4d6e90 100644
--- a/src/poptint.h
+++ b/src/poptint.h
@@ -94,6 +94,7 @@ struct poptContext_s {
struct optionStackEntry * os;
poptArgv leftovers;
int numLeftovers;
+ int allocLeftovers;
int nextLeftover;
const struct poptOption * options;
int restLeftover;
--
2.27.0

Binary file not shown.

BIN
popt-1.19.tar.gz Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
Name: popt Name: popt
Version: 1.18 Version: 1.19
Release: 3 Release: 1
Summary: C library for parsing command line parameters Summary: C library for parsing command line parameters
License: MIT License: MIT
URL: https://github.com/rpm-software-management/popt/ URL: https://github.com/rpm-software-management/popt/
@ -10,8 +10,6 @@ Patch0: fix-obscure-iconv-mis-call-error-path-could-lead-to-.patch
Patch1: fix-handle-newly-added-asset-.-call-like-elsewhere.patch Patch1: fix-handle-newly-added-asset-.-call-like-elsewhere.patch
Patch2: fix-permit-reading-aliases-remove-left-over-goto-exi.patch Patch2: fix-permit-reading-aliases-remove-left-over-goto-exi.patch
Patch3: fix-coverity-CID-1057440-Unused-pointer-value-UNUSED.patch Patch3: fix-coverity-CID-1057440-Unused-pointer-value-UNUSED.patch
Patch4: backport-Consider-POPT_CONTEXT_KEEP_FIRST-during-reset.patch
Patch5: backport-Fix-incorrect-handling-of-leftovers-with-poptStuffAr.patch
BuildRequires: gcc git gettext BuildRequires: gcc git gettext
@ -77,10 +75,13 @@ make check
%{_libdir}/lib%{name}.a %{_libdir}/lib%{name}.a
%files help %files help
%doc CHANGES README %doc README
%{_mandir}/man3/%{name}.3.gz %{_mandir}/man3/%{name}.3.gz
%changelog %changelog
* Fri Nov 18 2022 dillon chen <dillon.chen@gmail.com> - 1.19-1
- update to 1.19
* Thu Aug 18 2022 zhangruifang <zhangruifang1@h-partners.com> - 1.18-3 * Thu Aug 18 2022 zhangruifang <zhangruifang1@h-partners.com> - 1.18-3
- Revert fix memory leak regressions in popt - Revert fix memory leak regressions in popt