From bf6c4196fd017d54329de76f8730a69207e90801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Tue, 15 Dec 2020 12:12:40 +0100 Subject: [PATCH] mesh: Fix overflow of ivu_duration value Bluetooth Mesh require minimum limit time to enter iv update state or return to iv nornal state. For Zephyr bluetooth mesh implementation, use`ivu_duration` type `uint8_t` to represent current time, but if the time is more than 255 hours, there will be problems due to the overflow of 8-bit unassigned variables. This is port of f105455ebe6930c5004d46ffdc996aafa18fc593 --- nimble/host/mesh/src/net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nimble/host/mesh/src/net.c b/nimble/host/mesh/src/net.c index e802f5339..8b86935d3 100644 --- a/nimble/host/mesh/src/net.c +++ b/nimble/host/mesh/src/net.c @@ -815,7 +815,8 @@ done: static void ivu_refresh(struct ble_npl_event *work) { - bt_mesh.ivu_duration += BT_MESH_IVU_HOURS; + bt_mesh.ivu_duration = MIN(UINT8_MAX, + bt_mesh.ivu_duration + BT_MESH_IVU_HOURS); BT_DBG("%s for %u hour%s", atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS) ?