hoist check for backslash-EOL to after backslash
authorAlan T. DeKok <aland@freeradius.org>
Wed, 31 Aug 2016 14:21:36 +0000 (10:21 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 31 Aug 2016 14:26:27 +0000 (10:26 -0400)
src/lib/token.c

index 0ef4065..bb184df 100644 (file)
@@ -259,7 +259,7 @@ static FR_TOKEN getthing(char const **ptr, char *buf, int buflen, bool tok,
                } /* else there was a quotation character */
 
                /*
-                *      Un-escaped quotation character.  We're done.
+                *      Un-escaped quote character.  We're done.
                 */
                if (*p == quote) {
                        end = true;
@@ -267,11 +267,22 @@ static FR_TOKEN getthing(char const **ptr, char *buf, int buflen, bool tok,
                        break;
                }
 
+               /*
+                *      Everything but backslash gets copied over.
+                */
                if (*p != '\\') {
                        *s++ = *p++;
                        continue;
                }
 
+               /*
+                *      There's nothing after the backslash, it's an error.
+                */
+               if (!p[1]) {
+                       fr_strerror_printf("Unterminated string");
+                       return T_INVALID;
+               }
+
                if (unescape) {
                        p++;
 
@@ -285,10 +296,7 @@ static FR_TOKEN getthing(char const **ptr, char *buf, int buflen, bool tok,
                                case 't':
                                        *s++ = '\t';
                                        break;
-                               case '\0':
-                                       *s++ = '\\';
-                                       p--; /* force EOS */
-                                       break;
+
                                default:
                                        if (*p >= '0' && *p <= '9' &&
                                            sscanf(p, "%3o", &x) == 1) {
@@ -306,8 +314,6 @@ static FR_TOKEN getthing(char const **ptr, char *buf, int buflen, bool tok,
                         *      escaped characters into their non-escaped
                         *      equivalent.
                         */
-                       if (!p[1]) continue; /* force end of string */
-
                        if (p[1] == quote) { /* convert '\'' --> ' */
                                p++;
                        } else {