From: Timo Sirainen Date: Mon, 9 Nov 2020 15:52:51 +0000 (+0200) Subject: lib-index: Add explicit wrapping to 8bit variable increments X-Git-Tag: 2.3.14.rc1~366 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ddf77cf384385b96c115a9b96354816c40803524;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Add explicit wrapping to 8bit variable increments Fixes ubsan errors: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned) --- diff --git a/src/lib-index/mail-cache-lookup.c b/src/lib-index/mail-cache-lookup.c index a9d20e3136..c0695e4154 100644 --- a/src/lib-index/mail-cache-lookup.c +++ b/src/lib-index/mail-cache-lookup.c @@ -330,7 +330,8 @@ static int mail_cache_seq(struct mail_cache_view *view, uint32_t seq) struct mail_cache_iterate_field field; int ret; - if (++view->cached_exists_value == 0) { + view->cached_exists_value = (view->cached_exists_value + 1) % UINT8_MAX; + if (view->cached_exists_value == 0) { /* wrapped, we'll have to clear the buffer */ buffer_set_used_size(view->cached_exists_buf, 0); view->cached_exists_value++; diff --git a/src/lib-index/mail-cache-purge.c b/src/lib-index/mail-cache-purge.c index 907310053a..c61c071295 100644 --- a/src/lib-index/mail-cache-purge.c +++ b/src/lib-index/mail-cache-purge.c @@ -293,7 +293,8 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans, ctx.new_msg = seq >= first_new_seq; buffer_set_used_size(ctx.buffer, 0); - if (++ctx.field_seen_value == 0) { + ctx.field_seen_value = (ctx.field_seen_value + 1) % UINT8_MAX; + if (ctx.field_seen_value == 0) { memset(buffer_get_modifiable_data(ctx.field_seen, NULL), 0, buffer_get_size(ctx.field_seen)); ctx.field_seen_value++;