2020-01-15 17:09:34

by Jakub Witowski

[permalink] [raw]
Subject: [PATCH 1/1] mesh: sequence number out of range fix

---
mesh/mesh-config-json.c | 4 ++++
mesh/net.c | 3 +++
2 files changed, 7 insertions(+)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 755caab0e..3ee3317d9 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -40,6 +40,7 @@
#include "mesh/mesh-defs.h"
#include "mesh/util.h"
#include "mesh/mesh-config.h"
+#include "mesh/net.h"

/* To prevent local node JSON cache thrashing, minimum update times */
#define MIN_SEQ_CACHE_TRIGGER 32
@@ -2019,6 +2020,9 @@ bool mesh_config_write_seq_number(struct mesh_config *cfg, uint32_t seq,
if (cached < seq + MIN_SEQ_CACHE_VALUE)
cached = seq + MIN_SEQ_CACHE_VALUE;

+ if (cached >= SEQ_MASK)
+ cached = SEQ_MASK;
+
l_debug("Seq Cache: %d -> %d", seq, cached);

cfg->write_seq = seq;
diff --git a/mesh/net.c b/mesh/net.c
index f0f0dbdbd..10dfd5dd3 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -511,6 +511,9 @@ uint32_t mesh_net_next_seq_num(struct mesh_net *net)
{
uint32_t seq = net->seq_num++;

+ if (net->seq_num > SEQ_MASK)
+ net->seq_num = SEQ_MASK;
+
node_set_sequence_number(net->node, net->seq_num);
return seq;
}
--
2.20.1