Skip to content
Snippets Groups Projects
Commit 4d8f8da7 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Limited the length of identifiers.

parent 2bdf696e
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
#include "lib.h"
#include "compat.h"
#include "str.h"
#include "str-sanitize.h"
#include "istream.h"
#include "sieve-common.h"
......@@ -560,12 +561,15 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexer *lexer)
/* Scan the rest of the identifier */
while ( IS_ALPHA(sieve_lexer_curchar(lexer)) ||
IS_ALPHA(sieve_lexer_curchar(lexer)) ||
IS_DIGIT(sieve_lexer_curchar(lexer)) ||
sieve_lexer_curchar(lexer) == '_' ) {
str_append_c(str, sieve_lexer_curchar(lexer));
if ( str_len(str) <= SIEVE_MAX_IDENTIFIER_LEN ) {
str_append_c(str, sieve_lexer_curchar(lexer));
}
sieve_lexer_shift(lexer);
}
/* Is this in fact a multiline text string ? */
if ( sieve_lexer_curchar(lexer) == ':' &&
type == STT_IDENTIFIER && str_len(str) == 4 &&
......@@ -674,6 +678,15 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexer *lexer)
lexer->token_type = STT_ERROR;
return FALSE;
}
if ( str_len(str) > SIEVE_MAX_IDENTIFIER_LEN ) {
sieve_lexer_error(lexer,
"encountered impossibly long %s%s'",
(type == STT_TAG ? "tag identifier ':" : "identifier '"),
str_sanitize(str_c(str), SIEVE_MAX_IDENTIFIER_LEN));
lexer->token_type = STT_ERROR;
return FALSE;
}
lexer->token_type = type;
return TRUE;
......
......@@ -6,6 +6,7 @@
*/
#define SIEVE_MAX_STRING_LEN (1 << 20)
#define SIEVE_MAX_IDENTIFIER_LEN 32
/*
* AST
......
......@@ -17,7 +17,7 @@ test "Lexer errors (FIXME: count only)" {
test_fail "compile should have failed.";
}
if not test_error :count "eq" :comparator "i;ascii-numeric" "8" {
if not test_error :count "eq" :comparator "i;ascii-numeric" "10" {
test_fail "wrong number of errors reported";
}
}
......
......@@ -2,7 +2,12 @@
* Lexer tests
*
* Total errors: 7 (+1 = 8)
*/
*/
/*
* Number limits
*/
# Number too large
if size :under 4294967300 {
stop;
......@@ -52,3 +57,15 @@ if size :under 4294967294 {
if size :under 1G {
stop;
}
/*
* Identifier limits
*/
if this_is_a_rediculously_long_test_name {
stop;
}
if test :this_is_an_even_more_rediculously_long_tagged_argument_name {
stop;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.