popt/popt-1.16-execfail.patch
Troy Dawson 8e5a0313a5 RHEL 9.0.0 Alpha bootstrap
The content of this branch was automatically imported from Fedora ELN
with the following as its source:
https://src.fedoraproject.org/rpms/popt#b7599d5d03e76f94f7734d9b0761ff66ec4400b4
2020-10-14 16:26:30 -07:00

72 lines
2.4 KiB
Diff

Patch by Panu Matilainen <pmatilai@redhat.com> for popt <= 1.16 which kludges
poptBadOption() to return something semi-meaningful on exec alias fail:
- poptBadOption() is totally unaware of exec alias failures, and will return
either the first argument or last option, giving wonderfully misleading error
messages (#697435, #710267).
- Remember execvp() first argument on failure and return that from
poptBadOption() if present to give the user a reasonable clue what exactly
went wrong.
This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.html
--- popt-1.16/popt.c 2010-01-19 01:39:10.000000000 +0100
+++ popt-1.16/popt.c.execfail 2013-11-24 15:50:06.000000000 +0100
@@ -192,6 +192,7 @@
con->flags = flags;
con->execs = NULL;
con->numExecs = 0;
+ con->execFail = NULL;
con->finalArgvAlloced = argc * 2;
con->finalArgv = calloc( (size_t)con->finalArgvAlloced, sizeof(*con->finalArgv) );
con->execAbsolute = 1;
@@ -236,6 +237,7 @@
con->nextLeftover = 0;
con->restLeftover = 0;
con->doExec = NULL;
+ con->execFail = _free(con->execFail);
if (con->finalArgv != NULL)
for (i = 0; i < con->finalArgvCount; i++) {
@@ -564,6 +566,7 @@
/*@-nullstate@*/
rc = execvp(argv[0], (char *const *)argv);
/*@=nullstate@*/
+ con->execFail = xstrdup(argv[0]);
exit:
if (argv) {
@@ -1697,11 +1700,19 @@
const char * poptBadOption(poptContext con, unsigned int flags)
{
struct optionStackEntry * os = NULL;
+ const char *badOpt = NULL;
- if (con != NULL)
- os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
+ if (con != NULL) {
+ /* Stupid hack to return something semi-meaningful from exec failure */
+ if (con->execFail) {
+ badOpt = con->execFail;
+ } else {
+ os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
+ badOpt = os->argv[os->next - 1];
+ }
+ }
- return (os != NULL && os->argv != NULL ? os->argv[os->next - 1] : NULL);
+ return badOpt;
}
const char * poptStrerror(const int error)
--- popt-1.16/poptint.h 2010-01-19 01:39:10.000000000 +0100
+++ popt-1.16/poptint.h.execfail 2013-11-24 15:50:38.000000000 +0100
@@ -132,6 +132,7 @@
/*@owned@*/ /*@null@*/
poptItem execs;
int numExecs;
+ char * execFail;
/*@only@*/ /*@null@*/
poptArgv finalArgv;
int finalArgvCount;