X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/bc93ee842fd5dd2a1cc2b2cb25656a98c673d772..e4c598c830234fe3def0bae6ba45ca54071a9ee5:/popt/poptparse.c diff --git a/popt/poptparse.c b/popt/poptparse.c index ccc2ac82..e003a04a 100644 --- a/popt/poptparse.c +++ b/popt/poptparse.c @@ -8,6 +8,8 @@ #include "system.h" +#include "poptint.h" + #define POPT_ARGV_ARRAY_GROW_DELTA 5 /*@-boundswrite@*/ @@ -81,7 +83,7 @@ int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr) if (*src != quote) *buf++ = '\\'; } *buf++ = *src; - } else if (isspace(*src)) { + } else if (isSpace(src)) { if (*argv[argc] != '\0') { buf++, argc++; if (argc == argvAlloced) { @@ -157,25 +159,27 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl p = line; /* loop until first non-space char or EOL */ - while( *p != '\0' && isspace(*p) ) + while( *p != '\0' && isSpace(p) ) p++; linelen = strlen(p); - if (linelen >= maxlinelen-1) + if (linelen >= maxlinelen-1) { + free(argstr); 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 != '=') + while (*q != '\0' && (!isSpace(q)) && *q != '=') q++; - if (isspace(*q)) { + if (isSpace(q)) { /* a space after the name, find next non space */ *q++='\0'; - while( *q != '\0' && isspace((int)*q) ) q++; + while( *q != '\0' && isSpace(q) ) q++; } if (*q == '\0') { /* single command line option (ie, no name=val, just name) */ @@ -186,8 +190,8 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl argstr = realloc(argstr, maxargvlen); if (argstr == NULL) return POPT_ERROR_MALLOC; } - strcat(argstr, " --"); - strcat(argstr, p); + strlcat(argstr, " --", maxargvlen); + strlcat(argstr, p, maxargvlen); continue; } if (*q != '=') @@ -197,14 +201,14 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl *q++ = '\0'; /* find next non-space letter of value */ - while (*q != '\0' && isspace(*q)) + 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)) + while (isSpace(--x)) *x = 0; /* null out last char if space (including fgets() NL) */ /* rest of line accept */ @@ -215,11 +219,11 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl argstr = realloc(argstr, maxargvlen); if (argstr == NULL) return POPT_ERROR_MALLOC; } - strcat(argstr, " --"); - strcat(argstr, p); - strcat(argstr, "=\""); - strcat(argstr, q); - strcat(argstr, "\""); + strlcat(argstr, " --", maxargvlen); + strlcat(argstr, p, maxargvlen); + strlcat(argstr, "=\"", maxargvlen); + strlcat(argstr, q, maxargvlen); + strlcat(argstr, "\"", maxargvlen); } *argstrp = argstr;