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>
Tue, 26 Feb 2013 17:42:28 +0000 (17:42 +0000)
src/include/radiusd.h
src/main/util.c

index bbfb491..4b98979 100644 (file)
@@ -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);
index 42cd53f..13a8ca7 100644 (file)
@@ -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;