]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix parsing of malformed quoted squid.conf strings (#2239) auto master
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Mon, 15 Sep 2025 14:22:01 +0000 (14:22 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 15 Sep 2025 14:51:21 +0000 (14:51 +0000)
Iteration of a quoted token that ends with a backslash (escape with no
next char) kept going past the end of the token. That bug as well as
hypothetical 2KB-byte tokens (exceeding CONFIG_LINE_LIMIT) could also
result in a 1-byte NUL overrun.

src/ConfigParser.cc

index 283856675f174d9bcbff85ad50ab246278220ed3..4794763cc8679885882ad1d538d1f07aaac5deb5 100644 (file)
@@ -146,8 +146,13 @@ ConfigParser::UnQuote(const char *token, const char **next)
     const char  *s = token + 1;
     char *d = UnQuoted;
     /* scan until the end of the quoted string, handling escape sequences*/
-    while (*s && *s != quoteChar && !errorStr && (size_t)(d - UnQuoted) < sizeof(UnQuoted)) {
+    while (*s && *s != quoteChar && !errorStr && (size_t)(d - UnQuoted) < sizeof(UnQuoted) - 1) {
         if (*s == '\\') {
+            if (s[1] == '\0') {
+                errorStr = "Unterminated escape sequence";
+                errorPos = s;
+                break;
+            }
             s++;
             switch (*s) {
             case 'r':