popt-1.16-execfail

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


Gbp-Pq: Name popt-1.16-execfail.patch
This commit is contained in:
Michael Jeanson 2022-05-16 15:33:04 +08:00 committed by openKylinBot
parent cbe2be231d
commit 5136634f38
2 changed files with 15 additions and 3 deletions

17
popt.c
View File

@ -193,6 +193,7 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv,
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;
@ -237,6 +238,7 @@ void poptResetContext(poptContext con)
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++) {
@ -565,6 +567,7 @@ if (_popt_debug)
/*@-nullstate@*/
rc = execvp(argv[0], (char *const *)argv);
/*@=nullstate@*/
con->execFail = xstrdup(argv[0]);
exit:
if (argv) {
@ -1727,11 +1730,19 @@ int poptAddItem(poptContext con, poptItem newItem, int flags)
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)

View File

@ -133,6 +133,7 @@ struct poptContext_s {
/*@owned@*/ /*@null@*/
poptItem execs;
int numExecs;
char * execFail;
/*@only@*/ /*@null@*/
poptArgv finalArgv;
int finalArgvCount;