From: Josef 'Jeff' Sipek Date: Thu, 20 May 2021 15:05:37 +0000 (-0400) Subject: lib: event filter - Return invalid chars in the lexer X-Git-Tag: 2.3.16~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d386e3727f3a1797f9729ea9866619a0a43e0687;p=thirdparty%2Fdovecot%2Fcore.git lib: event filter - Return invalid chars in the lexer This way, we leave it up to the parser to figure out whether or not they make sense. --- diff --git a/src/lib/event-filter-lexer.l b/src/lib/event-filter-lexer.l index f1d5f9b593..08af117789 100644 --- a/src/lib/event-filter-lexer.l +++ b/src/lib/event-filter-lexer.l @@ -74,13 +74,30 @@ static size_t event_filter_parser_input_proc(char *buf, size_t size, yyscan_t sc [A-Za-z0-9:.*?_-]+ { yylval->str = t_strdup(yytext); return TOKEN; } [ \t\n\r] { /* ignore */ } . { - char msg[160]; - - i_snprintf(msg, sizeof(msg), - "syntax error, unexpected character '%c'", - yytext[0]); - - event_filter_parser_error(yyextra, msg); + /* + * We simply return the char to the + * and let the grammar error out + * with a syntax error. + * + * Note: The cast is significant + * since utf-8 bytes >=128 will + * otherwise result in sign + * extension and a negative int + * getting returned on some + * platforms (e.g., x86) which in + * turn confuses the parser. E.g., + * if: + * *yytext = '\x80' + * we get: + * *yytext -> -128 + * (int) *yytext -> -128 + * which is wrong. With the + * unsigned char cast, we get: + * (u.c.) *yytext -> 128 + * (int)(u.c.) *yytext -> 128 + * which is correct. + */ + return (unsigned char) *yytext; } %% #ifdef __clang__ diff --git a/src/lib/test-event-filter-parser.c b/src/lib/test-event-filter-parser.c index c7973d7ea5..3cfb7fe461 100644 --- a/src/lib/test-event-filter-parser.c +++ b/src/lib/test-event-filter-parser.c @@ -128,6 +128,9 @@ static struct test { } tests[] = { GOOD("", ""), + /* unquoted tokens can be only [a-zA-Z0-9:.*?_-]+ */ + BAD("abc=r\xcc\x8c", "event filter: syntax error"), + /* check that spaces and extra parens don't break anything */ #define CHECK_REAL(sp1, key, sp2, sp3, value, sp4) \ GOOD(sp1 key sp2 "=" sp3 value sp4, \