]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: event filter - Return invalid chars in the lexer
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Thu, 20 May 2021 15:05:37 +0000 (11:05 -0400)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 25 May 2021 10:26:58 +0000 (10:26 +0000)
This way, we leave it up to the parser to figure out whether or not they
make sense.

src/lib/event-filter-lexer.l
src/lib/test-event-filter-parser.c

index f1d5f9b59301ff13e3e74463a11c5fd500024ce7..08af117789044b2b0b5d33a4ad3867af324497a2 100644 (file)
@@ -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__
index c7973d7ea51c4a0f1879ca97bbd19aad2067c0cf..3cfb7fe461b0a2623a72f53ccde2b1a610d2421b 100644 (file)
@@ -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, \