[popt] - Hack poptBadOption() to return something semi-meaningful on exec alias failures (#697435, #71026

Panu Matilainen pmatilai at fedoraproject.org
Thu Aug 2 13:20:03 UTC 2012


commit 69ee8930bc7a7a05524eb7f69e321f384ee6d7a8
Author: Panu Matilainen <pmatilai at redhat.com>
Date:   Thu Aug 2 16:16:49 2012 +0300

    - Hack poptBadOption() to return something semi-meaningful on exec alias
      failures (#697435, #710267)

 popt-1.13-execfail.patch |   70 ++++++++++++++++++++++++++++++++++++++++++++++
 popt.spec                |    8 ++++-
 2 files changed, 77 insertions(+), 1 deletions(-)
---
diff --git a/popt-1.13-execfail.patch b/popt-1.13-execfail.patch
new file mode 100644
index 0000000..83b58dc
--- /dev/null
+++ b/popt-1.13-execfail.patch
@@ -0,0 +1,70 @@
+Kludge 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.
+
+diff -up popt-1.13/popt.c.execfail popt-1.13/popt.c
+--- popt-1.13/popt.c.execfail	2012-08-02 16:08:34.762315304 +0300
++++ popt-1.13/popt.c	2012-08-02 16:11:41.352683721 +0300
+@@ -186,6 +186,7 @@ poptContext poptGetContext(const char *
+     con->flags = flags;
+     con->execs = NULL;
+     con->numExecs = 0;
++    con->execFail = NULL;
+     con->finalArgvAlloced = argc * 2;
+     con->finalArgv = calloc( con->finalArgvAlloced, sizeof(*con->finalArgv) );
+     con->execAbsolute = 1;
+@@ -234,6 +235,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++) {
+@@ -468,6 +470,7 @@ if (_popt_debug)
+ /*@-nullstate@*/
+     rc = execvp(argv[0], (char *const *)argv);
+ /*@=nullstate@*/
++    con->execFail = xstrdup(argv[0]);
+ 
+ exit:
+     if (argv) {
+@@ -1194,11 +1197,19 @@ int poptAddItem(poptContext con, poptIte
+ 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)
+diff -up popt-1.13/poptint.h.execfail popt-1.13/poptint.h
+--- popt-1.13/poptint.h.execfail	2012-08-02 16:08:34.000000000 +0300
++++ popt-1.13/poptint.h	2012-08-02 16:12:35.796500122 +0300
+@@ -78,6 +78,7 @@ struct poptContext_s {
+ /*@owned@*/ /*@null@*/
+     poptItem execs;
+     int numExecs;
++    char * execFail;
+ /*@only@*/ /*@null@*/
+     const char ** finalArgv;
+     int finalArgvCount;
diff --git a/popt.spec b/popt.spec
index 55b83ac..44b3770 100644
--- a/popt.spec
+++ b/popt.spec
@@ -1,7 +1,7 @@
 Summary:	C library for parsing command line parameters
 Name:		popt
 Version:	1.13
-Release:	11%{?dist}
+Release:	12%{?dist}
 License:	MIT
 Group:		System Environment/Libraries
 URL:		http://www.rpm5.org/
@@ -9,6 +9,7 @@ Source:		http://www.rpm5.org/files/%{name}/%{name}-%{version}.tar.gz
 Patch0:		popt-1.13-multilib.patch
 Patch1:		popt-1.13-popt_fprintf.patch
 Patch2:		popt-1.13-alias-equal-arg.patch
+Patch3:		popt-1.13-execfail.patch
 BuildRequires:	gettext, doxygen, graphviz
 BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
@@ -46,6 +47,7 @@ Install it if you need to link statically with libpopt.
 %patch0 -p1 -b .multilib
 %patch1 -p1 -b .popt_fprintf
 %patch2 -p1 -b .alias-equal-arg
+%patch3 -p1 -b .execfail
 
 %build
 %configure --libdir=/%{_lib}
@@ -94,6 +96,10 @@ rm -rf $RPM_BUILD_ROOT
 %{_libdir}/libpopt.a
 
 %changelog
+* Thu Aug 02 2012 Panu Matilainen <pmatilai at redhat.com> - 1.13-12
+- Hack poptBadOption() to return something semi-meaningful on exec alias
+  failures (#697435, #710267)
+
 * Sat Jul 21 2012 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.13-11
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild
 


More information about the scm-commits mailing list