diff mbox series

[1/1] mesh: sequence number out of range fix

Message ID 20200115170830.7479-2-jakub.witowski@silvair.com
State New
Headers show
Series [1/1] mesh: sequence number out of range fix | expand

Commit Message

Jakub Witowski Jan. 15, 2020, 5:08 p.m. UTC
---
 mesh/mesh-config-json.c | 4 ++++
 mesh/net.c              | 3 +++
 2 files changed, 7 insertions(+)
diff mbox series

Patch

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;
 }