]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove quotes from quoted argv entries
authorBrian Candler <b.candler@pobox.com>
Fri, 8 Feb 2013 18:55:56 +0000 (18:55 +0000)
committerBrian Candler <b.candler@pobox.com>
Fri, 15 Feb 2013 09:13:41 +0000 (09:13 +0000)
src/include/radiusd.h
src/main/util.c

index 8261652905aebcb626fed39dabaebda61dacf785..7b0ae530e8e7224171013386042e789751d9313f 100644 (file)
@@ -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,
index 53c62d816b8ee7ea518362100605b4c55664abdb..0a948958ff46b58a6a916dc47015e56634fd5fd4 100644 (file)
@@ -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;