ctx.lookup_fn = lookup_fn ? lookup_fn : ap_expr_lookup_default;
ctx.at_start = 1;
-
- /*
- * Be sure to avoid overflows in the scanner. In practice the input length
- * will be limited by the config file parser, anyway.
- * XXX: The scanner really should do proper buffer overflow checks
- */
- if (ctx.inputlen >= MAX_STRING_LEN)
- return "Expression too long";
-
ap_expr_yylex_init(&ctx.scanner);
ap_expr_yyset_extra(&ctx, ctx.scanner);
rc = ap_expr_yyparse(&ctx);
#define YY_EXTRA_TYPE ap_expr_parse_ctx_t*
-#define PERROR(msg) yyextra->error2 = msg ; return T_ERROR;
+#define PERROR(msg) do { yyextra->error2 = msg ; return T_ERROR; } while (0)
#define str_ptr (yyextra->scan_ptr)
#define str_buf (yyextra->scan_buf)
#define str_del (yyextra->scan_del)
+#define STR_APPEND(c) do { \
+ *str_ptr++ = (c); \
+ if (str_ptr >= str_buf + sizeof(str_buf)) \
+ PERROR("String too long"); \
+ } while (0)
+
%}
}
}
else {
- *str_ptr++ = yytext[0];
+ STR_APPEND(yytext[0]);
}
}
<str,var,vararg>\n {
PERROR("Escape sequence out of bound");
}
else {
- *str_ptr++ = result;
+ STR_APPEND(result);
}
}
<str,vararg>\\[0-9]+ {
PERROR("Bad escape sequence");
}
-<str,vararg>\\n { *str_ptr++ = '\n'; }
-<str,vararg>\\r { *str_ptr++ = '\r'; }
-<str,vararg>\\t { *str_ptr++ = '\t'; }
-<str,vararg>\\b { *str_ptr++ = '\b'; }
-<str,vararg>\\f { *str_ptr++ = '\f'; }
-<str,vararg>\\(.|\n) {
- *str_ptr++ = yytext[1];
-}
+<str,vararg>\\n { STR_APPEND('\n'); }
+<str,vararg>\\r { STR_APPEND('\r'); }
+<str,vararg>\\t { STR_APPEND('\t'); }
+<str,vararg>\\b { STR_APPEND('\b'); }
+<str,vararg>\\f { STR_APPEND('\f'); }
+<str,vararg>\\(.|\n) { STR_APPEND(yytext[1]); }
/* regexp backref inside string/arg */
<str,vararg>[$][0-9] {
<str,vararg>[^\\\n"'%}$]+ {
char *cp = yytext;
- while (*cp != '\0')
- *str_ptr++ = *cp++;
+ while (*cp != '\0') {
+ STR_APPEND(*cp);
+ cp++;
+ }
}
/* variable inside string/arg */
}
<vararg>[%$] {
- *str_ptr++ = yytext[0];
+ STR_APPEND(yytext[0]);
}
<str>[%}$] {
- *str_ptr++ = yytext[0];
+ STR_APPEND(yytext[0]);
}
%\{ {
}
else {
*regex_ptr++ = yytext[0];
+ if (regex_ptr >= regex_buf + sizeof(regex_buf))
+ PERROR("Regexp too long");
}
}
<regex_flags>i {