From: Brian Candler Date: Fri, 8 Feb 2013 18:55:56 +0000 (+0000) Subject: Remove quotes from quoted argv entries X-Git-Tag: release_3_0_0_beta1~917^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d35dc18a1fad332a0c0d2af35279b2eed9a22b4;p=thirdparty%2Ffreeradius-server.git Remove quotes from quoted argv entries --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index bbfb491f670..4b98979a516 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -623,6 +623,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_pps(int *past, int *present, time_t *then, struct timeval *now); diff --git a/src/main/util.c b/src/main/util.c index 42cd53fb80f..13a8ca7f610 100644 --- a/src/main/util.c +++ b/src/main/util.c @@ -583,6 +583,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. @@ -751,12 +778,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, "rad_expand_xlat: Invalid string passed as argument"); return -1; } - from += length; + from += length+2; to += length; break;