Group :: Sistema/Bibliotecas
RPM: libpopt
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: popt-1.18-alt-context-checks.patch
Download
Download
diff --git a/popt/src/popt.c b/popt/src/popt.c
index 2db2bbd..0e8fd62 100644
--- a/popt/src/popt.c
+++ b/popt/src/popt.c
@@ -63,6 +63,7 @@ static void prtcon(const char *msg, poptContext con)
void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
{
+ if (con == NULL) return;
con->execPath = _free(con->execPath);
con->execPath = xstrdup(path);
con->execAbsolute = allowAbsolute;
@@ -71,7 +72,7 @@ void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt)
{
- if (opt != NULL)
+ if (con == NULL || opt == NULL) return;
for (; opt->longName || opt->shortName || opt->arg; opt++) {
poptArg arg = { .ptr = opt->arg };
if (arg.ptr)
@@ -91,7 +92,7 @@ static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt)
static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt)
{
- if (opt != NULL)
+ if (con == NULL || opt == NULL) return;
for (; opt->longName || opt->shortName || opt->arg; opt++) {
poptArg arg = { .ptr = opt->arg };
if (arg.ptr)
@@ -117,7 +118,7 @@ static void invokeCallbacksOPTION(poptContext con,
const struct poptOption * cbopt = NULL;
poptArg cbarg = { .ptr = NULL };
- if (opt != NULL)
+ if (con == NULL || opt == NULL) return;
for (; opt->longName || opt->shortName || opt->arg; opt++) {
poptArg arg = { .ptr = opt->arg };
switch (poptArgType(opt)) {
@@ -235,7 +236,7 @@ static int handleExec(poptContext con,
poptItem item;
int i;
- if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
+ if (con == NULL || con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
return 0;
for (i = con->numExecs - 1; i >= 0; i--) {
@@ -328,7 +329,7 @@ static int handleAlias(poptContext con,
char shortName,
const char * nextArg)
{
- poptItem item = con->os->currAlias;
+ poptItem item = (con && con->os) ? con->os->currAlias : NULL;
int rc;
int i;
@@ -341,7 +342,7 @@ static int handleAlias(poptContext con,
return 0;
}
- if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
+ if (con == NULL || con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
return 0;
for (i = con->numAliases - 1; i >= 0; i--) {
@@ -440,7 +441,7 @@ const char * findProgramPath(const char * argv0)
static int execCommand(poptContext con)
{
- poptItem item = con->doExec;
+ poptItem item = con ? con->doExec : NULL;
poptArgv argv = NULL;
int argc = 0;
int rc;
@@ -608,9 +609,11 @@ findOption(const struct poptOption * opt,
static const char * findNextArg(poptContext con,
unsigned argx, int delete_arg)
{
- struct optionStackEntry * os = con->os;
+ struct optionStackEntry * os = con ? con->os : NULL;
const char * arg;
+ if (os == NULL || con->optionStack == NULL) return NULL;
+
do {
int i;
arg = NULL;
@@ -645,6 +648,8 @@ expandNextArg(poptContext con, const char * s)
size_t tn = strlen(s) + 1;
char c;
+ if (con == NULL) return NULL;
+
te = t = malloc(tn);
if (t == NULL) return NULL; /* XXX can't happen */
*t = '\0';
@@ -1544,6 +1549,9 @@ int poptAddAlias(poptContext con, struct poptAlias alias,
{
struct poptItem_s item_buf;
poptItem item = &item_buf;
+
+ if (con == NULL) return 1;
+
memset(item, 0, sizeof(*item));
item->option.longName = alias.longName;
item->option.shortName = alias.shortName;
@@ -1562,6 +1570,8 @@ int poptAddItem(poptContext con, poptItem newItem, int flags)
poptItem * items, item;
int * nitems;
+ if (con == NULL) return 1;
+
switch (flags) {
case 1:
items = &con->execs;
@@ -1643,6 +1653,8 @@ const char * poptStrerror(const int error)
return POPT_("config file failed sanity test");
case POPT_ERROR_ERRNO:
return strerror(errno);
+ case POPT_ERROR_NOCONTEXT:
+ return POPT_("no context");
default:
return POPT_("unknown error");
}
@@ -1653,6 +1665,9 @@ int poptStuffArgs(poptContext con, const char ** argv)
int argc;
int rc;
+ if (con == NULL)
+ return POPT_ERROR_NOCONTEXT;
+
if ((con->os - con->optionStack) == POPT_OPTION_DEPTH)
return POPT_ERROR_OPTSTOODEEP;
@@ -1673,7 +1688,7 @@ int poptStuffArgs(poptContext con, const char ** argv)
const char * poptGetInvocationName(poptContext con)
{
- return (con->os->argv ? con->os->argv[0] : "");
+ return ((con && con->os->argv) ? con->os->argv[0] : "");
}
int poptStrippedArgv(poptContext con, int argc, char ** argv)
@@ -1682,14 +1697,14 @@ int poptStrippedArgv(poptContext con, int argc, char ** argv)
int j = 1;
int i;
- if (con->arg_strip)
+ if (con && con->arg_strip)
for (i = 1; i < argc; i++) {
if (PBM_ISSET(i, con->arg_strip))
numargs--;
}
for (i = 1; i < argc; i++) {
- if (con->arg_strip && PBM_ISSET(i, con->arg_strip))
+ if (con && con->arg_strip && PBM_ISSET(i, con->arg_strip))
continue;
argv[j] = (j < numargs) ? argv[i] : NULL;
j++;
diff --git a/popt/src/popt.h b/popt/src/popt.h
index 38a5478..edc1946 100644
--- a/popt/src/popt.h
+++ b/popt/src/popt.h
@@ -100,7 +100,9 @@
#define POPT_ERROR_BADOPERATION -19 /*!< mutually exclusive logical operations requested */
#define POPT_ERROR_NULLARG -20 /*!< opt->arg should not be NULL */
#define POPT_ERROR_MALLOC -21 /*!< memory allocation failed */
-#define POPT_ERROR_BADCONFIG -22 /*!< config file failed sanity test */
+#define POPT_ERROR_NOCONTEXT -22 /*!< no context */
+#define POPT_ERROR_BADCONFIG -23 /*!< config file failed sanity test */
+
/*@}*/
/** \ingroup popt
diff --git a/popt/src/poptconfig.c b/popt/src/poptconfig.c
index 9d97ccd..d846bb9 100644
--- a/popt/src/poptconfig.c
+++ b/popt/src/poptconfig.c
@@ -199,7 +199,7 @@ static int configAppMatch(poptContext con, const char * s)
{
int rc = 1;
- if (con->appName == NULL) /* XXX can't happen. */
+ if (con == NULL || con->appName == NULL) /* XXX can't happen. */
return rc;
#if defined(HAVE_GLOB_H) && defined(HAVE_FNMATCH_H)
@@ -228,7 +228,7 @@ static int poptConfigLine(poptContext con, char * line)
int i, j;
int rc = POPT_ERROR_BADCONFIG;
- if (con->appName == NULL)
+ if (con == NULL || con->appName == NULL)
goto exit;
memset(item, 0, sizeof(*item));
@@ -343,6 +343,8 @@ int poptReadConfigFile(poptContext con, const char * fn)
char *t, *te;
int rc;
+ if (con == NULL) return POPT_ERROR_NOCONTEXT;
+
if ((rc = poptReadFile(fn, &b, &nb, POPT_READFILE_TRIMNEWLINES)) != 0)
return (errno == ENOENT ? 0 : rc);
if (b == NULL || nb == 0)
@@ -434,7 +436,7 @@ int poptReadDefaultConfig(poptContext con, UNUSED(int useEnv))
struct stat sb;
int rc = 0; /* assume success */
- if (con->appName == NULL) goto exit;
+ if (con == NULL || con->appName == NULL) goto exit;
rc = poptReadConfigFile(con, POPT_SYSCONFDIR "/popt");
if (rc) goto exit;
diff --git a/popt/src/popthelp.c b/popt/src/popthelp.c
index 3c05acb..ede202d 100644
--- a/popt/src/popthelp.c
+++ b/popt/src/popthelp.c
@@ -571,6 +571,8 @@ static void singleTableHelp(poptContext con, FILE * fp,
const struct poptOption * opt;
const char *sub_transdom;
+ if (con == NULL) return;
+
if (table == poptAliasOptions) {
itemHelp(fp, con->aliases, con->numAliases, columns, NULL);
itemHelp(fp, con->execs, con->numExecs, columns, NULL);
@@ -631,6 +633,8 @@ void poptPrintHelp(poptContext con, FILE * fp, UNUSED(int flags))
{
columns_t columns = calloc((size_t)1, sizeof(*columns));
+ if (con == NULL) return;
+
(void) showHelpIntro(con, fp);
if (con->otherHelp)
POPT_fprintf(fp, " %s\n", con->otherHelp);
@@ -761,7 +765,7 @@ static size_t singleTableUsage(poptContext con, FILE * fp, columns_t columns,
const char * translation_domain,
poptDone done)
{
- if (opt != NULL)
+ if (con != NULL && opt != NULL)
for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
if (poptArgType(opt) == POPT_ARG_INTL_DOMAIN) {
translation_domain = (const char *)opt->arg;
@@ -850,6 +854,8 @@ void poptPrintUsage(poptContext con, FILE * fp, UNUSED(int flags))
struct poptDone_s done_buf;
poptDone done = &done_buf;
+ if (con == NULL) return;
+
memset(done, 0, sizeof(*done));
done->nopts = 0;
done->maxopts = 64;
@@ -881,6 +887,8 @@ void poptPrintUsage(poptContext con, FILE * fp, UNUSED(int flags))
void poptSetOtherOptionHelp(poptContext con, const char * text)
{
+ if (con == NULL) return;
+
con->otherHelp = _free(con->otherHelp);
con->otherHelp = xstrdup(text);
}