summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xconfigure.ac5
-rw-r--r--findme.c3
-rw-r--r--popt.c40
-rw-r--r--popt.h31
-rw-r--r--poptconfig.c22
-rw-r--r--popthelp.c23
-rw-r--r--poptint.h2
-rw-r--r--system.h9
8 files changed, 74 insertions, 61 deletions
diff --git a/configure.ac b/configure.ac
index 9170776..ac8f764 100755
--- a/configure.ac
+++ b/configure.ac
@@ -81,16 +81,17 @@ then
AC_MSG_RESULT(yes)
fi
-AC_CHECK_FUNCS(strerror mtrace getuid geteuid)
AC_CHECK_FUNC(setreuid, [], [
AC_CHECK_LIB(ucb, setreuid, [if echo $LIBS | grep -- -lucb >/dev/null ;then :; else LIBS="$LIBS -lc -lucb" USEUCB=y;fi])
])
+AC_CHECK_FUNCS(getuid geteuid mtrace __secure_getenv setregid strerror)
+
AM_GNU_GETTEXT
POPT_SOURCE_PATH="`pwd`"
AC_DEFINE_UNQUOTED(POPT_SOURCE_PATH, "$POPT_SOURCE_PATH",
- [Full path to popt top_sourcedir.])
+ [Full path to popt top_srcdir.])
AC_SUBST(POPT_SOURCE_PATH)
AC_OUTPUT([Doxyfile Makefile intl/Makefile po/Makefile.in])
diff --git a/findme.c b/findme.c
index a950e50..c4aaabc 100644
--- a/findme.c
+++ b/findme.c
@@ -9,7 +9,8 @@
#include "system.h"
#include "findme.h"
-const char * findProgramPath(const char * argv0) {
+const char * findProgramPath(const char * argv0)
+{
char * path = getenv("PATH");
char * pathbuf;
char * start, * chptr;
diff --git a/popt.c b/popt.c
index eb81c72..f306bd2 100644
--- a/popt.c
+++ b/popt.c
@@ -23,8 +23,9 @@
int _popt_debug = 0;
#endif
-#ifndef HAVE_STRERROR
-static char * strerror(int errno) {
+#if !defined(HAVE_STRERROR) && !defined(__LCLINT__)
+static char * strerror(int errno)
+{
extern int sys_nerr;
extern char * sys_errlist[];
@@ -36,7 +37,8 @@ static char * strerror(int errno) {
#endif
#ifdef MYDEBUG
-/*@unused@*/ static void prtcon(const char *msg, poptContext con)
+/*@unused@*/
+static void prtcon(const char *msg, poptContext con)
{
if (msg) fprintf(stderr, "%s", msg);
fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n",
@@ -54,7 +56,7 @@ void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
con->execPath = _free(con->execPath);
con->execPath = xstrdup(path);
con->execAbsolute = allowAbsolute;
- /*@-nullstate@*/ /* LCL: con->execPath can be NULL? */
+ /*@-nullstate@*/ /* LCL: con->execPath not NULL */
return;
/*@=nullstate@*/
}
@@ -75,9 +77,9 @@ static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt)
poptCallbackType cb = (poptCallbackType)opt->arg;
/*@=castfcnptr@*/
/* Perform callback. */
- /*@-moduncon -noeffectuncon @*/
+ /*@-noeffectuncon @*/
cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip);
- /*@=moduncon =noeffectuncon @*/
+ /*@=noeffectuncon @*/
}
}
}
@@ -98,9 +100,9 @@ static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt)
poptCallbackType cb = (poptCallbackType)opt->arg;
/*@=castfcnptr@*/
/* Perform callback. */
- /*@-moduncon -noeffectuncon @*/
+ /*@-noeffectuncon @*/
cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip);
- /*@=moduncon =noeffectuncon @*/
+ /*@=noeffectuncon @*/
}
}
}
@@ -138,10 +140,10 @@ static void invokeCallbacksOPTION(poptContext con,
const void * cbData = (cbopt->descrip ? cbopt->descrip : myData);
/* Perform callback. */
if (cb != NULL) { /* XXX program error */
- /*@-moduncon -noeffectuncon @*/
+ /*@-noeffectuncon @*/
cb(con, POPT_CALLBACK_REASON_OPTION, myOpt,
con->os->nextArg, cbData);
- /*@=moduncon =noeffectuncon @*/
+ /*@=noeffectuncon @*/
}
/* Terminate (unless explcitly continuing). */
if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE))
@@ -377,15 +379,14 @@ static int execCommand(poptContext con)
argv = malloc(sizeof(*argv) *
(6 + item->argc + con->numLeftovers + con->finalArgvCount));
- if (argv == NULL) return POPT_ERROR_MALLOC; /* XXX can't happen */
+ if (argv == NULL) return POPT_ERROR_MALLOC;
- if (!strchr(item->argv[0], '/') && con->execPath) {
+ if (!strchr(item->argv[0], '/') && con->execPath != NULL) {
char *s = alloca(strlen(con->execPath) + strlen(item->argv[0]) + sizeof("/"));
sprintf(s, "%s/%s", con->execPath, item->argv[0]);
argv[argc] = s;
- } else {
+ } else
argv[argc] = findProgramPath(item->argv[0]);
- }
if (argv[argc++] == NULL) return POPT_ERROR_NOARG;
if (item->argc > 1) {
@@ -400,9 +401,6 @@ static int execCommand(poptContext con)
}
if (con->leftovers != NULL && con->numLeftovers > 0) {
-#if 0
- argv[argc++] = "--";
-#endif
memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers);
argc += con->numLeftovers;
}
@@ -410,6 +408,8 @@ static int execCommand(poptContext con)
argv[argc] = NULL;
#ifdef __hpux
+ rc = setresgid(getgid(), getgid(),-1);
+ if (rc) return POPT_ERROR_ERRNO;
rc = setresuid(getuid(), getuid(),-1);
if (rc) return POPT_ERROR_ERRNO;
#else
@@ -419,10 +419,14 @@ static int execCommand(poptContext con)
* XXX from Norbert Warmuth <nwarmuth@privat.circular.de>
*/
#if defined(HAVE_SETUID)
+ rc = setgid(getgid());
+ if (rc) return POPT_ERROR_ERRNO;
rc = setuid(getuid());
if (rc) return POPT_ERROR_ERRNO;
#elif defined (HAVE_SETREUID)
- rc = setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */
+ rc = setregid(getgid(), getgid());
+ if (rc) return POPT_ERROR_ERRNO;
+ rc = setreuid(getuid(), getuid());
if (rc) return POPT_ERROR_ERRNO;
#else
; /* Can't drop privileges */
diff --git a/popt.h b/popt.h
index 7c84f30..d55c0fe 100644
--- a/popt.h
+++ b/popt.h
@@ -217,7 +217,8 @@ typedef void (*poptCallbackType) (poptContext con,
/*@null@*/ const struct poptOption * opt,
/*@null@*/ const char * arg,
/*@null@*/ const void * data)
- /*@*/;
+ /*@globals internalState @*/
+ /*@modifies internalState @*/;
/** \ingroup popt
* Initialize popt context.
@@ -257,7 +258,8 @@ int poptGetNextOpt(/*@null@*/poptContext con)
* @param con context
* @return option argument, NULL if no argument is available
*/
-/*@observer@*/ /*@null@*/ const char * poptGetOptArg(/*@null@*/poptContext con)
+/*@observer@*/ /*@null@*/
+const char * poptGetOptArg(/*@null@*/poptContext con)
/*@modifies con @*/;
/** \ingroup popt
@@ -265,7 +267,8 @@ int poptGetNextOpt(/*@null@*/poptContext con)
* @param con context
* @return next argument, NULL if no argument is available
*/
-/*@observer@*/ /*@null@*/ const char * poptGetArg(/*@null@*/poptContext con)
+/*@observer@*/ /*@null@*/
+const char * poptGetArg(/*@null@*/poptContext con)
/*@modifies con @*/;
/** \ingroup popt
@@ -273,7 +276,8 @@ int poptGetNextOpt(/*@null@*/poptContext con)
* @param con context
* @return current argument, NULL if no argument is available
*/
-/*@observer@*/ /*@null@*/ const char * poptPeekArg(/*@null@*/poptContext con)
+/*@observer@*/ /*@null@*/
+const char * poptPeekArg(/*@null@*/poptContext con)
/*@*/;
/** \ingroup popt
@@ -281,7 +285,8 @@ int poptGetNextOpt(/*@null@*/poptContext con)
* @param con context
* @return argument array, NULL terminated
*/
-/*@observer@*/ /*@null@*/ const char ** poptGetArgs(/*@null@*/poptContext con)
+/*@observer@*/ /*@null@*/
+const char ** poptGetArgs(/*@null@*/poptContext con)
/*@modifies con @*/;
/** \ingroup popt
@@ -290,7 +295,8 @@ int poptGetNextOpt(/*@null@*/poptContext con)
* @param flags
* @return offending option
*/
-/*@observer@*/ const char * poptBadOption(/*@null@*/poptContext con, int flags)
+/*@observer@*/
+const char * poptBadOption(/*@null@*/poptContext con, int flags)
/*@*/;
/** \ingroup popt
@@ -298,7 +304,8 @@ int poptGetNextOpt(/*@null@*/poptContext con)
* @param con context
* @return NULL always
*/
-/*@null@*/ poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con)
+/*@null@*/
+poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con)
/*@modifies con @*/;
/** \ingroup popt
@@ -340,9 +347,9 @@ int poptAddItem(poptContext con, poptItem newItem, int flags)
* @return 0 on success, POPT_ERROR_ERRNO on failure
*/
int poptReadConfigFile(poptContext con, const char * fn)
- /*@globals fileSystem, internalState @*/
+ /*@globals errno, fileSystem, internalState @*/
/*@modifies con->execs, con->numExecs,
- fileSystem, internalState @*/;
+ errno, fileSystem, internalState @*/;
/** \ingroup popt
* Read default configuration from /etc/popt and $HOME/.popt.
@@ -443,7 +450,8 @@ int poptConfigFileToString(FILE *fp, /*@out@*/ char ** argstrp, int flags)
* @param error popt error
* @return error string
*/
-/*@observer@*/ const char *const poptStrerror(const int error)
+/*@observer@*/
+const char *const poptStrerror(const int error)
/*@*/;
/** \ingroup popt
@@ -491,7 +499,8 @@ void poptSetOtherOptionHelp(poptContext con, const char * text)
* @return argv[0]
*/
/*@-fcnuse@*/
-/*@observer@*/ const char * poptGetInvocationName(poptContext con)
+/*@observer@*/
+const char * poptGetInvocationName(poptContext con)
/*@*/;
/*@=fcnuse@*/
diff --git a/poptconfig.c b/poptconfig.c
index a600a92..e5cba45 100644
--- a/poptconfig.c
+++ b/poptconfig.c
@@ -8,25 +8,26 @@
#include "system.h"
#include "poptint.h"
+/*@access poptContext @*/
/*@-compmempass@*/ /* FIX: item->option.longName kept, not dependent. */
static void configLine(poptContext con, char * line)
/*@modifies con @*/
{
- /*@-type@*/
- int nameLength = strlen(con->appName);
- /*@=type@*/
+ size_t nameLength;
const char * entryType;
const char * opt;
poptItem item = alloca(sizeof(*item));
int i, j;
+
+ if (con->appName == NULL)
+ return;
+ nameLength = strlen(con->appName);
/*@-boundswrite@*/
memset(item, 0, sizeof(*item));
- /*@-type@*/
if (strncmp(line, con->appName, nameLength)) return;
- /*@=type@*/
line += nameLength;
if (*line == '\0' || !isspace(*line)) return;
@@ -108,9 +109,7 @@ int poptReadConfigFile(poptContext con, const char * fn)
if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
rc = errno;
(void) close(fd);
- /*@-mods@*/
errno = rc;
- /*@=mods@*/
return POPT_ERROR_ERRNO;
}
@@ -118,9 +117,7 @@ int poptReadConfigFile(poptContext con, const char * fn)
if (read(fd, (char *)file, fileLength) != fileLength) {
rc = errno;
(void) close(fd);
- /*@-mods@*/
errno = rc;
- /*@=mods@*/
return POPT_ERROR_ERRNO;
}
if (close(fd) == -1)
@@ -168,15 +165,10 @@ int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
char * fn, * home;
int rc;
- /*@-type@*/
- if (!con->appName) return 0;
- /*@=type@*/
+ if (con->appName == NULL) return 0;
rc = poptReadConfigFile(con, "/etc/popt");
if (rc) return rc;
-#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
- if (getuid() != geteuid()) return 0;
-#endif
if ((home = getenv("HOME"))) {
fn = alloca(strlen(home) + 20);
diff --git a/popthelp.c b/popthelp.c
index 34b5044..c7dd151 100644
--- a/popthelp.c
+++ b/popthelp.c
@@ -1,6 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/*@-type@*/
/** \ingroup popt
* \file popt/popthelp.c
*/
@@ -12,6 +11,8 @@
#include "system.h"
#include "poptint.h"
+/*@access poptContext@*/
+
/**
* Display arguments.
* @param con context
@@ -204,7 +205,7 @@ static void singleOptionHelp(FILE * fp, int maxLeftCol,
int lineLength = 79 - indentLength;
const char * help = D_(translation_domain, opt->descrip);
const char * argDescrip = getArgDescrip(opt, translation_domain);
- int helpLength;
+ size_t helpLength;
char * defs = NULL;
char * left;
int nb = maxLeftCol + 1;
@@ -489,9 +490,9 @@ static int showHelpIntro(poptContext con, FILE * fp)
fprintf(fp, POPT_("Usage:"));
if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
/*@-boundsread@*/
- /*@-nullderef@*/ /* LCL: wazzup? */
+ /*@-nullderef -type@*/ /* LCL: wazzup? */
fn = con->optionStack->argv[0];
- /*@=nullderef@*/
+ /*@=nullderef =type@*/
/*@=boundsread@*/
if (fn == NULL) return len;
if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1;
@@ -522,13 +523,13 @@ void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
* @param opt option(s)
* @param translation_domain translation domain
*/
-static int singleOptionUsage(FILE * fp, int cursor,
+static size_t singleOptionUsage(FILE * fp, size_t cursor,
const struct poptOption * opt,
/*@null@*/ const char *translation_domain)
/*@globals fileSystem @*/
/*@modifies *fp, fileSystem @*/
{
- int len = 4;
+ size_t len = 4;
char shortStr[2] = { '\0', '\0' };
const char * item = shortStr;
const char * argDescrip = getArgDescrip(opt, translation_domain);
@@ -582,7 +583,8 @@ static int singleOptionUsage(FILE * fp, int cursor,
* @param nitems no. of ara/exec entries
* @param translation_domain translation domain
*/
-static int itemUsage(FILE * fp, int cursor, poptItem item, int nitems,
+static size_t itemUsage(FILE * fp, size_t cursor,
+ /*@null@*/ poptItem item, int nitems,
/*@null@*/ const char * translation_domain)
/*@globals fileSystem @*/
/*@modifies *fp, fileSystem @*/
@@ -625,7 +627,7 @@ typedef struct poptDone_s {
* @param done tables already processed
* @return
*/
-static int singleTableUsage(poptContext con, FILE * fp, int cursor,
+static size_t singleTableUsage(poptContext con, FILE * fp, size_t cursor,
/*@null@*/ const struct poptOption * opt,
/*@null@*/ const char * translation_domain,
/*@null@*/ poptDone done)
@@ -708,14 +710,16 @@ static int showShortOptions(const struct poptOption * opt, FILE * fp,
void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
{
poptDone done = memset(alloca(sizeof(*done)), 0, sizeof(*done));
- int cursor;
+ size_t cursor;
done->nopts = 0;
done->maxopts = 64;
cursor = done->maxopts * sizeof(*done->opts);
/*@-boundswrite@*/
done->opts = memset(alloca(cursor), 0, cursor);
+ /*@-keeptrans@*/
done->opts[done->nopts++] = (const void *) con->options;
+ /*@=keeptrans@*/
/*@=boundswrite@*/
cursor = showHelpIntro(con, fp);
@@ -738,4 +742,3 @@ void poptSetOtherOptionHelp(poptContext con, const char * text)
con->otherHelp = _free(con->otherHelp);
con->otherHelp = xstrdup(text);
}
-/*@=type@*/
diff --git a/poptint.h b/poptint.h
index 5d308ef..5e75712 100644
--- a/poptint.h
+++ b/poptint.h
@@ -87,7 +87,7 @@ struct poptContext_s {
/*@only@*/
const char * execPath;
int execAbsolute;
-/*@only@*/
+/*@only@*/ /*@relnull@*/
const char * otherHelp;
/*@null@*/
pbm_set * arg_strip;
diff --git a/system.h b/system.h
index 1d1b9da..685860c 100644
--- a/system.h
+++ b/system.h
@@ -36,11 +36,11 @@ extern __const __int32_t *__ctype_toupper;
#endif
#if defined(__LCLINT__)
-/*@-declundef -incondefs -redecl@*/ /* LCL: missing annotation */
-/*@only@*/ void * alloca (size_t __size)
+/*@-declundef -incondefs @*/ /* LCL: missing annotation */
+/*@only@*/ /*@out@*/ void * alloca (size_t __size)
/*@ensures MaxSet(result) == (__size - 1) @*/
/*@*/;
-/*@=declundef =incondefs =redecl@*/
+/*@=declundef =incondefs @*/
#endif
/* AIX requires this to be the first thing in the file. */
@@ -72,5 +72,8 @@ char *alloca ();
#define xstrdup(_str) strdup(_str)
#endif /* HAVE_MCHECK_H && defined(__GNUC__) */
+#if HAVE___SECURE_GETENV && !defined(__LCLINT__)
+#define getenv(_s) __secure_getenv(_s)
+#endif
#include "popt.h"