From 0d35dc18a1fad332a0c0d2af35279b2eed9a22b4 Mon Sep 17 00:00:00 2001 From: Brian Candler Date: Fri, 8 Feb 2013 18:55:56 +0000 Subject: [PATCH] Remove quotes from quoted argv entries --- src/include/radiusd.h | 1 + src/main/util.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/include/radiusd.h b/src/include/radiusd.h index bbfb491..4b98979 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 42cd53f..13a8ca7 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; -- 2.1.4