Group :: Sistema/Bibliotecas
RPM: libpopt
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: popt-20020315-alt-context-checks.patch
Download
Download
diff -ur popt-20020315~/popt.c popt-20020315/popt.c
--- popt-20020315~/popt.c Mon Mar 25 14:03:27 2002
+++ popt-20020315/popt.c Mon Mar 25 14:06:26 2002
@@ -46,6 +46,7 @@
void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
{
+ if (!con) return;
con->execPath = _free(con->execPath);
con->execPath = xstrdup(path);
con->execAbsolute = allowAbsolute;
@@ -58,7 +59,7 @@
/*@globals internalState@*/
/*@modifies internalState@*/
{
- if (opt != NULL)
+ if (!con || !opt) return;
for (; opt->longName || opt->shortName || opt->arg; opt++) {
if (opt->arg == NULL) continue; /* XXX program error. */
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
@@ -81,7 +82,7 @@
/*@globals internalState@*/
/*@modifies internalState@*/
{
- if (opt != NULL)
+ if (!con || !opt) return;
for (; opt->longName || opt->shortName || opt->arg; opt++) {
if (opt->arg == NULL) continue; /* XXX program error. */
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
@@ -109,7 +110,7 @@
{
const struct poptOption * cbopt = NULL;
- if (opt != NULL)
+ if (!con || !opt) return;
for (; opt->longName || opt->shortName || opt->arg; opt++) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
/* Recurse on included sub-tables. */
@@ -207,9 +208,7 @@
void poptResetContext(poptContext con)
{
- int i;
-
- if (con == NULL) return;
+ if (!con) return;
while (con->os > con->optionStack) {
cleanOSE(con->os--);
}
@@ -225,10 +224,13 @@
con->doExec = NULL;
if (con->finalArgv != NULL)
+ {
+ int i;
for (i = 0; i < con->finalArgvCount; i++)
/*@-unqualifiedtrans@*/ /* FIX: typedef double indirection. */
con->finalArgv[i] = _free(con->finalArgv[i]);
/*@=unqualifiedtrans@*/
+ }
con->finalArgvCount = 0;
con->arg_strip = PBM_FREE(con->arg_strip);
@@ -247,7 +249,7 @@
poptItem item;
int i;
- if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
+ if (!con || con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
return 0;
for (i = con->numExecs - 1; i >= 0; i--) {
@@ -305,7 +307,7 @@
con->os->currAlias, con->os->currAlias->option.longName @*/
/*@modifies con @*/
{
- poptItem item = con->os->currAlias;
+ poptItem item = (con && con->os) ? con->os->currAlias : NULL;
int rc;
int i;
@@ -317,7 +319,7 @@
return 0;
}
- if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
+ if (!con || con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
return 0;
for (i = con->numAliases - 1; i >= 0; i--) {
@@ -353,7 +355,7 @@
static int execCommand(poptContext con)
/*@*/
{
- poptItem item = con->doExec;
+ poptItem item = con ? con->doExec : NULL;
const char ** argv;
int argc = 0;
int rc;
@@ -507,8 +509,10 @@
con->os->next, con->os->argb, con->os->argc, con->os->argv @*/
/*@modifies con @*/
{
- struct optionStackEntry * os = con->os;
+ struct optionStackEntry * os = con ? con->os : NULL;
const char * arg;
+
+ if (!os || !con->optionStack) return NULL;
do {
int i;
@@ -550,6 +554,7 @@
size_t tn = strlen(s) + 1;
char c;
+ if (!con) return NULL;
te = t = malloc(tn);;
if (t == NULL) return NULL; /* XXX can't happen */
while ((c = *s++) != '\0') {
@@ -593,6 +598,7 @@
/*@defines con->arg_strip @*/
/*@modifies con @*/
{
+ if (!con) return;
/*@-sizeoftype@*/
if (con->arg_strip == NULL)
con->arg_strip = PBM_ALLOC(con->optionStack[0].argc);
@@ -607,7 +613,7 @@
static int poptSaveLong(const struct poptOption * opt, long aLong)
/*@modifies opt->arg @*/
{
- if (opt->arg == NULL)
+ if (!opt || opt->arg == NULL)
return POPT_ERROR_NULLARG;
if (opt->argInfo & POPT_ARGFLAG_NOT)
@@ -1061,6 +1067,8 @@
/*@unused@*/ int flags)
{
poptItem item = alloca(sizeof(*item));
+
+ if (!con) return 1;
memset(item, 0, sizeof(*item));
item->option.longName = alias.longName;
item->option.shortName = alias.shortName;
@@ -1080,6 +1088,8 @@
poptItem * items, item;
int * nitems;
+ if (!con) return 1;
+
switch (flags) {
case 1:
items = &con->execs;
@@ -1152,6 +1162,8 @@
return POPT_("number too large or too small");
case POPT_ERROR_MALLOC:
return POPT_("memory allocation failed");
+ case POPT_ERROR_NOCONTEXT:
+ return POPT_("no context");
case POPT_ERROR_ERRNO:
return strerror(errno);
default:
@@ -1164,6 +1176,8 @@
int argc;
int rc;
+ if (!con) return POPT_ERROR_NOCONTEXT;
+
if ((con->os - con->optionStack) == POPT_OPTION_DEPTH)
return POPT_ERROR_OPTSTOODEEP;
@@ -1184,7 +1198,7 @@
const char * poptGetInvocationName(poptContext con)
{
- return (con->os->argv ? con->os->argv[0] : "");
+ return ((con && con->os && con->os->argv) ? con->os->argv[0] : "");
}
int poptStrippedArgv(poptContext con, int argc, char ** argv)
@@ -1194,14 +1208,14 @@
int i;
/*@-sizeoftype@*/
- 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 -ur popt-20020315~/popt.h popt-20020315/popt.h
--- popt-20020315~/popt.h Fri Mar 15 09:29:44 2002
+++ popt-20020315/popt.h Mon Mar 25 14:03:51 2002
@@ -90,6 +90,7 @@
#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_NOCONTEXT -22 /*!< no context */
/*@}*/
/** \ingroup popt
diff -ur popt-20020315~/poptconfig.c popt-20020315/poptconfig.c
--- popt-20020315~/poptconfig.c Fri Mar 15 09:29:44 2002
+++ popt-20020315/poptconfig.c Mon Mar 25 14:09:25 2002
@@ -14,13 +14,14 @@
/*@modifies con @*/
{
/*@-type@*/
- int nameLength = strlen(con->appName);
+ int nameLength = con ? strlen(con->appName) : 0;
/*@=type@*/
const char * entryType;
const char * opt;
poptItem item = alloca(sizeof(*item));
int i, j;
+ if (!con) return;
memset(item, 0, sizeof(*item));
/*@-type@*/
@@ -98,6 +99,8 @@
int fd, rc;
off_t fileLength;
+ if (!con) return POPT_ERROR_NOCONTEXT;
+
fd = open(fn, O_RDONLY);
if (fd < 0)
return (errno == ENOENT ? 0 : POPT_ERROR_ERRNO);
@@ -164,7 +167,7 @@
int rc;
/*@-type@*/
- if (!con->appName) return 0;
+ if (!con || !con->appName) return 0;
/*@=type@*/
rc = poptReadConfigFile(con, "/etc/popt");
diff -ur popt-20020315~/popthelp.c popt-20020315/popthelp.c
--- popt-20020315~/popthelp.c Fri Mar 15 09:29:44 2002
+++ popt-20020315/popthelp.c Mon Mar 25 14:03:51 2002
@@ -417,6 +417,8 @@
const struct poptOption * opt;
const char *sub_transdom;
+ if (!con) return;
+
if (table == poptAliasOptions) {
itemHelp(fp, con->aliases, con->numAliases, left, NULL);
itemHelp(fp, con->execs, con->numExecs, left, NULL);
@@ -457,9 +459,9 @@
const char * fn;
fprintf(fp, POPT_("Usage:"));
- if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
+ if (!(con && (con->flags & POPT_CONTEXT_KEEP_FIRST))) {
/*@-nullderef@*/ /* LCL: wazzup? */
- fn = con->optionStack->argv[0];
+ fn = (con && con->optionStack) ? con->optionStack->argv[0] : 0;
/*@=nullderef@*/
if (fn == NULL) return len;
if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1;
@@ -474,6 +476,8 @@
{
int leftColWidth;
+ if (!con) return;
+
(void) showHelpIntro(con, fp);
if (con->otherHelp)
fprintf(fp, " %s\n", con->otherHelp);
@@ -573,7 +577,7 @@
/*@modifies *fp, fileSystem @*/
{
/*@-branchstate@*/ /* FIX: W2DO? */
- if (opt != NULL)
+ if (con && opt)
for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) {
translation_domain = (const char *)opt->arg;
@@ -633,6 +637,8 @@
{
int cursor;
+ if (!con) return;
+
cursor = showHelpIntro(con, fp);
cursor += showShortOptions(con->options, fp, NULL);
(void) singleTableUsage(con, fp, cursor, con->options, NULL);
@@ -650,6 +656,7 @@
void poptSetOtherOptionHelp(poptContext con, const char * text)
{
+ if (!con) return;
con->otherHelp = _free(con->otherHelp);
con->otherHelp = xstrdup(text);
}