#include "var-expand-parser.h"
#include "expansion.h"
+#define MAX_PROGRAM_SIZE 8192
+
extern void var_expand_parser_lex_init_extra(void*, void*);
static const struct var_expand_params empty_params = {
int ret;
struct var_expand_parser_state state;
i_zero(&state);
+
+ if (strlen(str) > MAX_PROGRAM_SIZE) {
+ *error_r = t_strdup_printf("Program size exceeds maximum of %d bytes",
+ MAX_PROGRAM_SIZE);
+ return -1;
+ }
+
pool_t pool =
pool_alloconly_create(MEMPOOL_GROWING"var expand program", 1024);
state.p = state.plist = p_new(pool, struct var_expand_program, 1);
{ .in = "%{literal(\"\\\"\\\\hello\\\\world\\\"\")}", .out = "'\"\\hello\\world\"'", .ret = 0 },
/* Unsupported escape sequence */
{ .in = "%{literal('\\z')}", .out = "Invalid character escape", .ret = -1 },
+#define STR10(x) x x x x x x x x x x
+#define STR100(x) STR10(x) STR10(x) STR10(x) STR10(x) STR10(x) STR10(x) STR10(x) STR10(x) STR10(x) STR10(x)
+ /* Too long content */
+ {
+ .in = STR100("0123456789012345678901234567890123456789"
+ "0123456789012345678901234567890123456789"
+ "01234567890123456789"),
+ .out = "Program size exceeds maximum of 8192 bytes",
+ .ret = -1,
+ },
+
};
const struct var_expand_params params = {