Skip to content

Commit

Permalink
lib-sieve: variables extension: Respect UTF-8 character sequence boun…
Browse files Browse the repository at this point in the history
…daries when truncating variables.
  • Loading branch information
stephanbosch committed Jun 28, 2018
1 parent 92caa9e commit daf4a72
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib-sieve/plugins/variables/ext-variables-common.c
Expand Up @@ -611,7 +611,7 @@ bool sieve_variable_assign

/* Just a precaution, caller should prevent this in the first place */
if ( str_len(varval) > config->max_variable_size )
str_truncate(varval, config->max_variable_size);
str_truncate_utf8(varval, config->max_variable_size);

return TRUE;
}
Expand All @@ -632,7 +632,7 @@ bool sieve_variable_assign_cstr

/* Just a precaution, caller should prevent this in the first place */
if ( str_len(varval) > config->max_variable_size )
str_truncate(varval, config->max_variable_size);
str_truncate_utf8(varval, config->max_variable_size);

return TRUE;
}
Expand Down
11 changes: 8 additions & 3 deletions src/lib-sieve/plugins/variables/ext-variables-modifiers.c
Expand Up @@ -482,8 +482,13 @@ int sieve_variables_modifiers_apply
unsigned int i, modf_count;

/* Hold value within limits */
if ( str_len(*value) > config->max_variable_size )
str_truncate(*value, config->max_variable_size);
if ( str_len(*value) > config->max_variable_size ) {
/* assume variable originates from code, so copy it first */
string_t *new_value = t_str_new(config->max_variable_size+3);
str_append_str(new_value, *value);
*value = new_value;
str_truncate_utf8(*value, config->max_variable_size);
}

if ( !array_is_created(modifiers) )
return SIEVE_EXEC_OK;
Expand Down Expand Up @@ -513,7 +518,7 @@ int sieve_variables_modifiers_apply

/* Hold value within limits */
if ( str_len(*value) > config->max_variable_size )
str_truncate(*value, config->max_variable_size);
str_truncate_utf8(*value, config->max_variable_size);
}
}
return SIEVE_EXEC_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/lib-sieve/plugins/variables/ext-variables-operands.c
Expand Up @@ -267,7 +267,7 @@ static int opr_match_value_read
if ( *str_r == NULL )
*str_r = t_str_new(0);
else if ( str_len(*str_r) > config->max_variable_size )
str_truncate(*str_r, config->max_variable_size);
str_truncate_utf8(*str_r, config->max_variable_size);
}

return SIEVE_EXEC_OK;
Expand Down

0 comments on commit daf4a72

Please sign in to comment.