Be more restrictive on bad input
authorAlan T. DeKok <aland@freeradius.org>
Sat, 3 Oct 2009 18:07:22 +0000 (20:07 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 5 Oct 2009 15:13:25 +0000 (17:13 +0200)
Addresses bug #27

src/lib/token.c
src/main/conffile.c

index f8b6ed3..e161f78 100644 (file)
@@ -74,7 +74,7 @@ static FR_TOKEN getthing(const char **ptr, char *buf, int buflen, int tok,
 {
        char *s;
        const char *p;
-       int     quote;
+       int     quote, end = 0;
        int     escape;
        unsigned int    x;
        const FR_NAME_NUMBER*t;
@@ -112,6 +112,7 @@ static FR_TOKEN getthing(const char **ptr, char *buf, int buflen, int tok,
            (*p == '\'') ||
            (*p == '`')) {
                quote = *p;
+               end = 0;
                p++;
        }
        s = buf;
@@ -148,6 +149,7 @@ static FR_TOKEN getthing(const char **ptr, char *buf, int buflen, int tok,
                        continue;
                }
                if (quote && (*p == quote)) {
+                       end = 1;
                        p++;
                        break;
                }
@@ -166,6 +168,11 @@ static FR_TOKEN getthing(const char **ptr, char *buf, int buflen, int tok,
        }
        *s++ = 0;
 
+       if (quote && !end) {
+               fr_strerror_printf("Unterminated string");
+               return T_OP_INVALID;
+       }
+
        /* Skip whitespace again. */
        while (*p && isspace((int) *p))
                p++;
index 7f255c7..64b68ad 100644 (file)
@@ -1521,6 +1521,12 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp,
                case T_OP_SET:
                do_set:
                        t3 = getstring(&ptr, buf3, sizeof(buf3));
+                       if (t3 == T_OP_INVALID) {
+                               radlog(L_ERR, "%s[%d]: Parse error: %s",
+                                      filename, *lineno,
+                                      fr_strerror());
+                               return -1;
+                       }
 
                        /*
                         *      Handle variable substitution via ${foo}