wrowe 02/02/27 09:37:00
Modified: strings apr_cpystrn.c
Log:
Someone wasn't minding the p's and q's ... forgot to advance over a
trailing quote - so we always bombed by allocating too few entries
in the char* vector. Also, many use cases will presume a trailing
NULL entry in the argv, need to put one there.
Revision Changes Path
1.9 +17 -22 apr/strings/apr_cpystrn.c
Index: apr_cpystrn.c
===================================================================
RCS file: /home/cvs/apr/strings/apr_cpystrn.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- apr_cpystrn.c 25 Jul 2001 16:09:35 -0000 1.8
+++ apr_cpystrn.c 27 Feb 2002 17:37:00 -0000 1.9
@@ -125,8 +125,8 @@
apr_pool_t *token_context)
{
const char *cp;
- const char *tmpCnt;
- int isquoted, numargs = 0, rc = APR_SUCCESS;
+ const char *ct;
+ int isquoted, numargs = 0;
#define SKIP_WHITESPACE(cp) \
for ( ; *cp == ' ' || *cp == '\t'; ) { \
@@ -159,44 +159,39 @@
cp = arg_str;
SKIP_WHITESPACE(cp);
- tmpCnt = cp;
+ ct = cp;
/* This is ugly and expensive, but if anyone wants to figure a
* way to support any number of args without counting and
* allocating, please go ahead and change the code.
+ *
+ * Must account for the trailing NULL arg.
*/
- while (*tmpCnt != '\0') {
- CHECK_QUOTATION(tmpCnt, isquoted);
- DETERMINE_NEXTSTRING(tmpCnt, isquoted);
+ numargs = 1;
+ while (*ct != '\0') {
+ CHECK_QUOTATION(ct, isquoted);
+ DETERMINE_NEXTSTRING(ct, isquoted);
+ ct++;
numargs++;
- SKIP_WHITESPACE(tmpCnt);
- }
-
- *argv_out = apr_palloc(token_context, (numargs + 1)*sizeof(char*));
- if (*argv_out == NULL) {
- return (APR_ENOMEM);
+ SKIP_WHITESPACE(ct);
}
+ *argv_out = apr_palloc(token_context, numargs * sizeof(char*));
/* determine first argument */
numargs = 0;
while (*cp != '\0') {
CHECK_QUOTATION(cp, isquoted);
- tmpCnt = cp;
+ ct = cp;
DETERMINE_NEXTSTRING(cp, isquoted);
cp++;
- (*argv_out)[numargs] = apr_palloc(token_context, cp - tmpCnt);
- apr_cpystrn((*argv_out)[numargs], tmpCnt, cp - tmpCnt);
+ (*argv_out)[numargs] = apr_palloc(token_context, cp - ct);
+ apr_cpystrn((*argv_out)[numargs], ct, cp - ct);
numargs++;
- /* This needs to be -1 because we move past the end above. */
- if (*(cp - 1) == '\0') {
- (*argv_out)[numargs] = '\0';
- break;
- }
-
SKIP_WHITESPACE(cp);
}
+ (*argv_out)[numargs] = NULL;
- return(rc);
+ return APR_SUCCESS;
}
/* Filename_of_pathname returns the final element of the pathname.