From: Brian Candler Date: Fri, 8 Feb 2013 18:55:56 +0000 (+0000) Subject: Remove quotes from quoted argv entries X-Git-Tag: release_2_2_1~141^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abe18fb123a64bfc9b8d14372fc7da55426a31f6;p=thirdparty%2Ffreeradius-server.git Remove quotes from quoted argv entries --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 8261652905a..7b0ae530e8e 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -497,6 +497,7 @@ void *request_data_get(REQUEST *request, void *request_data_reference(REQUEST *request, void *unique_ptr, int unique_int); int rad_copy_string(char *dst, const char *src); +int rad_copy_string_bare(char *dst, const char *src); int rad_copy_variable(char *dst, const char *from); int rad_expand_xlat(REQUEST *request, const char *cmd, int max_argc, const char *argv[], int can_fail, diff --git a/src/main/util.c b/src/main/util.c index 53c62d816b8..0a948958ff4 100644 --- a/src/main/util.c +++ b/src/main/util.c @@ -533,6 +533,33 @@ int rad_copy_string(char *to, const char *from) return length; } +/* + * Copy a quoted string but without the quotes. The length + * returned is the number of chars written; the number of + * characters consumed is 2 more than this. + */ +int rad_copy_string_bare(char *to, const char *from) +{ + int length = 0; + char quote = *from; + + from++; + while (*from && (*from != quote)) { + if (*from == '\\') { + *(to++) = *(from++); + length++; + } + *(to++) = *(from++); + length++; + } + + if (*from != quote) return -1; /* not properly quoted */ + + *to = '\0'; + + return length; +} + /* * Copy a %{} string. @@ -660,12 +687,12 @@ int rad_expand_xlat(REQUEST *request, const char *cmd, switch (*from) { case '"': case '\'': - length = rad_copy_string(to, from); + length = rad_copy_string_bare(to, from); if (length < 0) { radlog(L_ERR|L_CONS, "rad_expand_xlat: Invalid string passed as argument"); return -1; } - from += length; + from += length+2; to += length; break;