summaryrefslogtreecommitdiff
path: root/strings/apr_cpystrn.c
diff options
context:
space:
mode:
authortrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2002-08-21 17:37:12 +0000
committertrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2002-08-21 17:37:12 +0000
commitadcdd57eb3f7be9ab067cc54805da6d16ce26d5a (patch)
tree4fc5a449df70b31c7b8206f01eba11bc8d62737b /strings/apr_cpystrn.c
parent8238c39018b6c0af18bebcb27062be2359a02a94 (diff)
downloadlibapr-adcdd57eb3f7be9ab067cc54805da6d16ce26d5a.tar.gz
Fix apr_tokenize_to_argv() to remove the escape character
(backslash) from the argument tokens. PR: 11793 Submitted by: Paul J. Reder Reviewed by: Jeff Trawick git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63824 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings/apr_cpystrn.c')
-rw-r--r--strings/apr_cpystrn.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/strings/apr_cpystrn.c b/strings/apr_cpystrn.c
index 7c56a25fa..f99eb92fc 100644
--- a/strings/apr_cpystrn.c
+++ b/strings/apr_cpystrn.c
@@ -126,6 +126,8 @@ APR_DECLARE(apr_status_t) apr_tokenize_to_argv(const char *arg_str,
{
const char *cp;
const char *ct;
+ char *cleaned, *dirty;
+ int escaped;
int isquoted, numargs = 0, argnum;
#define SKIP_WHITESPACE(cp) \
@@ -138,6 +140,10 @@ APR_DECLARE(apr_status_t) apr_tokenize_to_argv(const char *arg_str,
if (*cp == '"') { \
isquoted = 1; \
cp++; \
+ } \
+ else if (*cp == '\'') { \
+ isquoted = 2; \
+ cp++; \
}
/* DETERMINE_NEXTSTRING:
@@ -147,15 +153,35 @@ APR_DECLARE(apr_status_t) apr_tokenize_to_argv(const char *arg_str,
#define DETERMINE_NEXTSTRING(cp,isquoted) \
for ( ; *cp != '\0'; cp++) { \
if ( (isquoted && (*cp == ' ' || *cp == '\t')) \
- || (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t'))) { \
+ || (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t' || \
+ *(cp+1) == '"' || *(cp+1) == '\''))) { \
cp++; \
continue; \
} \
if ( (!isquoted && (*cp == ' ' || *cp == '\t')) \
- || (isquoted && *cp == '"') ) { \
+ || (isquoted == 1 && *cp == '"') \
+ || (isquoted == 2 && *cp == '\'') ) { \
break; \
} \
}
+
+/* REMOVE_ESCAPE_CHARS:
+ * Compresses the arg string to remove all of the '\' escape chars.
+ * The final argv strings should not have any extra escape chars in it.
+ */
+#define REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped) \
+ escaped = 0; \
+ while(*dirty) { \
+ if (!escaped && *dirty == '\\') { \
+ escaped = 1; \
+ } \
+ else { \
+ escaped = 0; \
+ *cleaned++ = *dirty; \
+ } \
+ ++dirty; \
+ } \
+ *cleaned = 0; /* last line of macro... */
cp = arg_str;
SKIP_WHITESPACE(cp);
@@ -187,6 +213,8 @@ APR_DECLARE(apr_status_t) apr_tokenize_to_argv(const char *arg_str,
cp++;
(*argv_out)[argnum] = apr_palloc(token_context, cp - ct);
apr_cpystrn((*argv_out)[argnum], ct, cp - ct);
+ cleaned = dirty = (*argv_out)[argnum];
+ REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped);
SKIP_WHITESPACE(cp);
}
(*argv_out)[argnum] = NULL;