Commit bc93ee84 authored by Wayne Davison's avatar Wayne Davison

- Upgraded popt to version 1.10.2.

- Modified all sprintf() and strcpy() calls to use snprintf()
  and strlcpy().
parent 0c6d7952
...@@ -2,18 +2,20 @@ ...@@ -2,18 +2,20 @@
* \file popt/findme.c * \file popt/findme.c
*/ */
/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING /* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from file accompanying popt source distributions, available from
ftp://ftp.rpm.org/pub/rpm/dist. */ ftp://ftp.rpm.org/pub/rpm/dist. */
#include "system.h" #include "system.h"
#include "findme.h" #include "findme.h"
const char * findProgramPath(const char * argv0) { const char * findProgramPath(const char * argv0)
{
char * path = getenv("PATH"); char * path = getenv("PATH");
char * pathbuf; char * pathbuf;
char * start, * chptr; char * start, * chptr;
char * buf; char * buf;
size_t bufsize;
if (argv0 == NULL) return NULL; /* XXX can't happen */ if (argv0 == NULL) return NULL; /* XXX can't happen */
/* If there is a / in the argv[0], it has to be an absolute path */ /* If there is a / in the argv[0], it has to be an absolute path */
...@@ -22,17 +24,20 @@ const char * findProgramPath(const char * argv0) { ...@@ -22,17 +24,20 @@ const char * findProgramPath(const char * argv0) {
if (path == NULL) return NULL; if (path == NULL) return NULL;
start = pathbuf = alloca(strlen(path) + 1); bufsize = strlen(path) + 1;
buf = malloc(strlen(path) + strlen(argv0) + sizeof("/")); start = pathbuf = alloca(bufsize);
if (pathbuf == NULL) return NULL; /* XXX can't happen */
strlcpy(pathbuf, path, bufsize);
bufsize += sizeof "/" - 1 + strlen(argv0);
buf = malloc(bufsize);
if (buf == NULL) return NULL; /* XXX can't happen */ if (buf == NULL) return NULL; /* XXX can't happen */
strcpy(pathbuf, path);
chptr = NULL; chptr = NULL;
/*@-branchstate@*/ /*@-branchstate@*/
do { do {
if ((chptr = strchr(start, ':'))) if ((chptr = strchr(start, ':')))
*chptr = '\0'; *chptr = '\0';
sprintf(buf, "%s/%s", start, argv0); snprintf(buf, bufsize, "%s/%s", start, argv0);
if (!access(buf, X_OK)) if (!access(buf, X_OK))
return buf; return buf;
......
This diff is collapsed.
This diff is collapsed.
...@@ -2,30 +2,32 @@ ...@@ -2,30 +2,32 @@
* \file popt/poptconfig.c * \file popt/poptconfig.c
*/ */
/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING /* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from file accompanying popt source distributions, available from
ftp://ftp.rpm.org/pub/rpm/dist. */ ftp://ftp.rpm.org/pub/rpm/dist. */
#include "system.h" #include "system.h"
#include "poptint.h" #include "poptint.h"
/*@access poptContext @*/
/*@-compmempass@*/ /* FIX: item->option.longName kept, not dependent. */ /*@-compmempass@*/ /* FIX: item->option.longName kept, not dependent. */
static void configLine(poptContext con, unsigned char * line) static void configLine(poptContext con, char * line)
/*@modifies con @*/ /*@modifies con @*/
{ {
/*@-type@*/ size_t nameLength;
int nameLength = strlen(con->appName);
/*@=type@*/
const char * entryType; const char * entryType;
const char * opt; const char * opt;
poptItem item = (poptItem) alloca(sizeof(*item)); poptItem item = (poptItem) alloca(sizeof(*item));
int i, j; int i, j;
if (con->appName == NULL)
return;
nameLength = strlen(con->appName);
/*@-boundswrite@*/
memset(item, 0, sizeof(*item)); memset(item, 0, sizeof(*item));
/*@-type@*/
if (strncmp(line, con->appName, nameLength)) return; if (strncmp(line, con->appName, nameLength)) return;
/*@=type@*/
line += nameLength; line += nameLength;
if (*line == '\0' || !isspace(*line)) return; if (*line == '\0' || !isspace(*line)) return;
...@@ -80,6 +82,7 @@ static void configLine(poptContext con, unsigned char * line) ...@@ -80,6 +82,7 @@ static void configLine(poptContext con, unsigned char * line)
item->argc = j; item->argc = j;
} }
/*@=modobserver@*/ /*@=modobserver@*/
/*@=boundswrite@*/
/*@-nullstate@*/ /* FIX: item->argv[] may be NULL */ /*@-nullstate@*/ /* FIX: item->argv[] may be NULL */
if (!strcmp(entryType, "alias")) if (!strcmp(entryType, "alias"))
...@@ -92,9 +95,9 @@ static void configLine(poptContext con, unsigned char * line) ...@@ -92,9 +95,9 @@ static void configLine(poptContext con, unsigned char * line)
int poptReadConfigFile(poptContext con, const char * fn) int poptReadConfigFile(poptContext con, const char * fn)
{ {
const unsigned char * file, * chptr, * end; const char * file, * chptr, * end;
unsigned char * buf; char * buf;
/*@dependent@*/ unsigned char * dst; /*@dependent@*/ char * dst;
int fd, rc; int fd, rc;
off_t fileLength; off_t fileLength;
...@@ -106,9 +109,7 @@ int poptReadConfigFile(poptContext con, const char * fn) ...@@ -106,9 +109,7 @@ int poptReadConfigFile(poptContext con, const char * fn)
if (fileLength == -1 || lseek(fd, 0, 0) == -1) { if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
rc = errno; rc = errno;
(void) close(fd); (void) close(fd);
/*@-mods@*/
errno = rc; errno = rc;
/*@=mods@*/
return POPT_ERROR_ERRNO; return POPT_ERROR_ERRNO;
} }
...@@ -116,14 +117,13 @@ int poptReadConfigFile(poptContext con, const char * fn) ...@@ -116,14 +117,13 @@ int poptReadConfigFile(poptContext con, const char * fn)
if (read(fd, (char *)file, fileLength) != fileLength) { if (read(fd, (char *)file, fileLength) != fileLength) {
rc = errno; rc = errno;
(void) close(fd); (void) close(fd);
/*@-mods@*/
errno = rc; errno = rc;
/*@=mods@*/
return POPT_ERROR_ERRNO; return POPT_ERROR_ERRNO;
} }
if (close(fd) == -1) if (close(fd) == -1)
return POPT_ERROR_ERRNO; return POPT_ERROR_ERRNO;
/*@-boundswrite@*/
dst = buf = alloca(fileLength + 1); dst = buf = alloca(fileLength + 1);
chptr = file; chptr = file;
...@@ -155,6 +155,7 @@ int poptReadConfigFile(poptContext con, const char * fn) ...@@ -155,6 +155,7 @@ int poptReadConfigFile(poptContext con, const char * fn)
} }
} }
/*@=infloops@*/ /*@=infloops@*/
/*@=boundswrite@*/
return 0; return 0;
} }
...@@ -164,18 +165,16 @@ int poptReadDefaultConfig(poptContext con, /*@unused@*/ UNUSED(int useEnv)) ...@@ -164,18 +165,16 @@ int poptReadDefaultConfig(poptContext con, /*@unused@*/ UNUSED(int useEnv))
char * fn, * home; char * fn, * home;
int rc; int rc;
/*@-type@*/ if (con->appName == NULL) return 0;
if (!con->appName) return 0;
/*@=type@*/
rc = poptReadConfigFile(con, "/etc/popt"); rc = poptReadConfigFile(con, "/etc/popt");
if (rc) return rc; if (rc) return rc;
if (getuid() != geteuid()) return 0;
if ((home = getenv("HOME"))) { if ((home = getenv("HOME"))) {
fn = alloca(strlen(home) + 20); size_t bufsize = strlen(home) + 20;
strcpy(fn, home); fn = alloca(bufsize);
strcat(fn, "/.popt"); if (fn == NULL) return 0;
snprintf(fn, bufsize, "%s/.popt", home);
rc = poptReadConfigFile(con, fn); rc = poptReadConfigFile(con, fn);
if (rc) return rc; if (rc) return rc;
} }
......
This diff is collapsed.
...@@ -23,13 +23,17 @@ _free(/*@only@*/ /*@null@*/ const void * p) ...@@ -23,13 +23,17 @@ _free(/*@only@*/ /*@null@*/ const void * p)
} }
/* Bit mask macros. */ /* Bit mask macros. */
/*@-exporttype -redef @*/
typedef unsigned int __pbm_bits; typedef unsigned int __pbm_bits;
/*@=exporttype =redef @*/
#define __PBM_NBITS (8 * sizeof (__pbm_bits)) #define __PBM_NBITS (8 * sizeof (__pbm_bits))
#define __PBM_IX(d) ((d) / __PBM_NBITS) #define __PBM_IX(d) ((d) / __PBM_NBITS)
#define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS)) #define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
/*@-exporttype -redef @*/
typedef struct { typedef struct {
__pbm_bits bits[1]; __pbm_bits bits[1];
} pbm_set; } pbm_set;
/*@=exporttype =redef @*/
#define __PBM_BITS(set) ((set)->bits) #define __PBM_BITS(set) ((set)->bits)
#define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits)) #define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits))
...@@ -40,37 +44,53 @@ typedef struct { ...@@ -40,37 +44,53 @@ typedef struct {
struct optionStackEntry { struct optionStackEntry {
int argc; int argc;
/*@only@*/ /*@null@*/ const char ** argv; /*@only@*/ /*@null@*/
/*@only@*/ /*@null@*/ pbm_set * argb; const char ** argv;
/*@only@*/ /*@null@*/
pbm_set * argb;
int next; int next;
/*@only@*/ /*@null@*/ const char * nextArg; /*@only@*/ /*@null@*/
/*@keep@*/ /*@null@*/ const char * nextCharArg; const char * nextArg;
/*@dependent@*/ /*@null@*/ poptItem currAlias; /*@observer@*/ /*@null@*/
const char * nextCharArg;
/*@dependent@*/ /*@null@*/
poptItem currAlias;
int stuffed; int stuffed;
}; };
struct poptContext_s { struct poptContext_s {
struct optionStackEntry optionStack[POPT_OPTION_DEPTH]; struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
/*@dependent@*/ struct optionStackEntry * os; /*@dependent@*/
/*@owned@*/ /*@null@*/ const char ** leftovers; struct optionStackEntry * os;
/*@owned@*/ /*@null@*/
const char ** leftovers;
int numLeftovers; int numLeftovers;
int nextLeftover; int nextLeftover;
/*@keep@*/ const struct poptOption * options; /*@keep@*/
const struct poptOption * options;
int restLeftover; int restLeftover;
/*@only@*/ /*@null@*/ const char * appName; /*@only@*/ /*@null@*/
/*@only@*/ /*@null@*/ poptItem aliases; const char * appName;
/*@only@*/ /*@null@*/
poptItem aliases;
int numAliases; int numAliases;
int flags; int flags;
/*@owned@*/ /*@null@*/ poptItem execs; /*@owned@*/ /*@null@*/
poptItem execs;
int numExecs; int numExecs;
/*@only@*/ /*@null@*/ const char ** finalArgv; /*@only@*/ /*@null@*/
const char ** finalArgv;
int finalArgvCount; int finalArgvCount;
int finalArgvAlloced; int finalArgvAlloced;
/*@dependent@*/ /*@null@*/ poptItem doExec; /*@dependent@*/ /*@null@*/
/*@only@*/ const char * execPath; poptItem doExec;
/*@only@*/
const char * execPath;
int execAbsolute; int execAbsolute;
/*@only@*/ const char * otherHelp; /*@only@*/ /*@relnull@*/
/*@null@*/ pbm_set * arg_strip; const char * otherHelp;
/*@null@*/
pbm_set * arg_strip;
}; };
#ifdef HAVE_LIBINTL_H #ifdef HAVE_LIBINTL_H
...@@ -83,7 +103,7 @@ struct poptContext_s { ...@@ -83,7 +103,7 @@ struct poptContext_s {
#define _(foo) foo #define _(foo) foo
#endif #endif
#if defined(HAVE_DGETTEXT) && !defined(__LCLINT__) #if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
#define D_(dom, str) dgettext(dom, str) #define D_(dom, str) dgettext(dom, str)
#define POPT_(foo) D_("popt", foo) #define POPT_(foo) D_("popt", foo)
#else #else
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* \file popt/poptparse.c * \file popt/poptparse.c
*/ */
/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING /* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
file accompanying popt source distributions, available from file accompanying popt source distributions, available from
ftp://ftp.rpm.org/pub/rpm/dist. */ ftp://ftp.rpm.org/pub/rpm/dist. */
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define POPT_ARGV_ARRAY_GROW_DELTA 5 #define POPT_ARGV_ARRAY_GROW_DELTA 5
/*@-boundswrite@*/
int poptDupArgv(int argc, const char **argv, int poptDupArgv(int argc, const char **argv,
int * argcPtr, const char *** argvPtr) int * argcPtr, const char *** argvPtr)
{ {
...@@ -35,7 +36,7 @@ int poptDupArgv(int argc, const char **argv, ...@@ -35,7 +36,7 @@ int poptDupArgv(int argc, const char **argv,
/*@-branchstate@*/ /*@-branchstate@*/
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
argv2[i] = dst; argv2[i] = dst;
dst += strlen(strcpy(dst, argv[i])) + 1; dst += strlcpy(dst, argv[i], nb) + 1;
} }
/*@=branchstate@*/ /*@=branchstate@*/
argv2[argc] = NULL; argv2[argc] = NULL;
...@@ -50,11 +51,13 @@ int poptDupArgv(int argc, const char **argv, ...@@ -50,11 +51,13 @@ int poptDupArgv(int argc, const char **argv,
*argcPtr = argc; *argcPtr = argc;
return 0; return 0;
} }
/*@=boundswrite@*/
int poptParseArgvString(const unsigned char * s, int * argcPtr, const char *** argvPtr) /*@-bounds@*/
int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr)
{ {
const unsigned char * src; const char * src;
unsigned char quote = '\0'; char quote = '\0';
int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA; int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
const char ** argv = malloc(sizeof(*argv) * argvAlloced); const char ** argv = malloc(sizeof(*argv) * argvAlloced);
int argc = 0; int argc = 0;
...@@ -116,3 +119,109 @@ exit: ...@@ -116,3 +119,109 @@ exit:
if (argv) free(argv); if (argv) free(argv);
return rc; return rc;
} }
/*@=bounds@*/
/* still in the dev stage.
* return values, perhaps 1== file erro
* 2== line to long
* 3== umm.... more?
*/
int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int flags))
{
char line[999];
char * argstr;
char * p;
char * q;
char * x;
int t;
int argvlen = 0;
size_t maxlinelen = sizeof(line);
size_t linelen;
int maxargvlen = 480;
int linenum = 0;
*argstrp = NULL;
/* | this_is = our_line
* p q x
*/
if (fp == NULL)
return POPT_ERROR_NULLARG;
argstr = calloc(maxargvlen, sizeof(*argstr));
if (argstr == NULL) return POPT_ERROR_MALLOC;
while (fgets(line, (int)maxlinelen, fp) != NULL) {
linenum++;
p = line;
/* loop until first non-space char or EOL */
while( *p != '\0' && isspace(*p) )
p++;
linelen = strlen(p);
if (linelen >= maxlinelen-1)
return POPT_ERROR_OVERFLOW; /* XXX line too long */
if (*p == '\0' || *p == '\n') continue; /* line is empty */
if (*p == '#') continue; /* comment line */
q = p;
while (*q != '\0' && (!isspace(*q)) && *q != '=')
q++;
if (isspace(*q)) {
/* a space after the name, find next non space */
*q++='\0';
while( *q != '\0' && isspace((int)*q) ) q++;
}
if (*q == '\0') {
/* single command line option (ie, no name=val, just name) */
q[-1] = '\0'; /* kill off newline from fgets() call */
argvlen += (t = q - p) + (sizeof(" --")-1);
if (argvlen >= maxargvlen) {
maxargvlen = (t > maxargvlen) ? t*2 : maxargvlen*2;
argstr = realloc(argstr, maxargvlen);
if (argstr == NULL) return POPT_ERROR_MALLOC;
}
strcat(argstr, " --");
strcat(argstr, p);
continue;
}
if (*q != '=')
continue; /* XXX for now, silently ignore bogus line */
/* *q is an equal sign. */
*q++ = '\0';
/* find next non-space letter of value */
while (*q != '\0' && isspace(*q))
q++;
if (*q == '\0')
continue; /* XXX silently ignore missing value */
/* now, loop and strip all ending whitespace */
x = p + linelen;
while (isspace(*--x))
*x = 0; /* null out last char if space (including fgets() NL) */
/* rest of line accept */
t = x - p;
argvlen += t + (sizeof("' --='")-1);
if (argvlen >= maxargvlen) {
maxargvlen = (t > maxargvlen) ? t*2 : maxargvlen*2;
argstr = realloc(argstr, maxargvlen);
if (argstr == NULL) return POPT_ERROR_MALLOC;
}
strcat(argstr, " --");
strcat(argstr, p);
strcat(argstr, "=\"");
strcat(argstr, q);
strcat(argstr, "\"");
}
*argstrp = argstr;
return 0;
}
...@@ -2,7 +2,17 @@ ...@@ -2,7 +2,17 @@
#include "config.h" #include "config.h"
#endif #endif
#if defined (__GLIBC__) && defined(__LCLINT__)
/*@-declundef@*/
/*@unchecked@*/
extern __const __int32_t *__ctype_tolower;
/*@unchecked@*/
extern __const __int32_t *__ctype_toupper;
/*@=declundef@*/
#endif
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
...@@ -19,12 +29,8 @@ ...@@ -19,12 +29,8 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#if !defined(__GNUC__) || defined(APPLE) #ifndef __GNUC__
/* Apparently the OS X port of gcc gags on __attribute__.
*
* <http://www.opensource.apple.com/bugs/X/gcc/2512150.html> */
#define __attribute__(x) #define __attribute__(x)
#endif #endif
#ifdef __NeXT #ifdef __NeXT
...@@ -34,11 +40,12 @@ ...@@ -34,11 +40,12 @@
#endif #endif
#if defined(__LCLINT__) #if defined(__LCLINT__)
/*@-declundef -incondefs -redecl@*/ /* LCL: missing annotation */ /*@-declundef -incondefs @*/ /* LCL: missing annotation */
/*@only@*/ void * alloca (size_t __size) /*@only@*/ /*@out@*/
void * alloca (size_t __size)
/*@ensures MaxSet(result) == (__size - 1) @*/ /*@ensures MaxSet(result) == (__size - 1) @*/
/*@*/; /*@*/;
/*@=declundef =incondefs =redecl@*/ /*@=declundef =incondefs @*/
#endif #endif
/* AIX requires this to be the first thing in the file. */ /* AIX requires this to be the first thing in the file. */
...@@ -49,7 +56,7 @@ ...@@ -49,7 +56,7 @@
# ifdef _AIX # ifdef _AIX
#pragma alloca #pragma alloca
# else # else
# if HAVE_ALLOCA # ifdef HAVE_ALLOCA
# ifndef alloca /* predefined by HP cc +Olibcalls */ # ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca (); char *alloca ();
# endif # endif
...@@ -66,7 +73,8 @@ char *alloca (); ...@@ -66,7 +73,8 @@ char *alloca ();
#endif #endif
/*@-redecl -redef@*/ /*@-redecl -redef@*/
/*@mayexit@*/ /*@only@*/ char * xstrdup (const char *str) /*@mayexit@*/ /*@only@*/ /*@unused@*/
char * xstrdup (const char *str)
/*@*/; /*@*/;
/*@=redecl =redef@*/ /*@=redecl =redef@*/
...@@ -77,6 +85,28 @@ char *alloca (); ...@@ -77,6 +85,28 @@ char *alloca ();
#define xstrdup(_str) strdup(_str) #define xstrdup(_str) strdup(_str)
#endif /* HAVE_MCHECK_H && defined(__GNUC__) */ #endif /* HAVE_MCHECK_H && defined(__GNUC__) */
#if HAVE___SECURE_GETENV && !defined(__LCLINT__)
#define getenv(_s) __secure_getenv(_s)
#endif
#ifndef HAVE_STRLCPY
size_t strlcpy(char *d, const char *s, size_t bufsize);
#endif
#ifndef HAVE_STRLCAT
size_t strlcat(char *d, const char *s, size_t bufsize);
#endif
#define UNUSED(x) x __attribute__((__unused__)) #define UNUSED(x) x __attribute__((__unused__))
#define PACKAGE "rsync"
#ifndef DBL_EPSILON
#define DBL_EPSILON 2.2204460492503131e-16
#endif
#ifdef _ABS
#undef _ABS
#endif
#include "popt.h" #include "popt.h"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment