linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Witowski <jakub.witowski@silvair.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 1/1] mesh: sequence number out of range fix
Date: Wed, 15 Jan 2020 18:08:30 +0100	[thread overview]
Message-ID: <20200115170830.7479-2-jakub.witowski@silvair.com> (raw)
In-Reply-To: <20200115170830.7479-1-jakub.witowski@silvair.com>

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


  reply	other threads:[~2020-01-15 17:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15 17:08 [PATCH 0/1] Sequence number out of range fix Jakub Witowski
2020-01-15 17:08 ` Jakub Witowski [this message]
2020-01-15 18:35 ` Gix, Brian
2020-01-15 19:09   ` michal.lowas-rzechonek
2020-01-15 19:53     ` Gix, Brian
2020-01-15 21:04       ` michal.lowas-rzechonek
2020-01-15 21:21         ` Gix, Brian
2020-01-15 22:02           ` michal.lowas-rzechonek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200115170830.7479-2-jakub.witowski@silvair.com \
    --to=jakub.witowski@silvair.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).