linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ] mesh: use explicit uint32_t when bit shifting left
@ 2022-03-30 21:17 Inga Stotland
  2022-03-30 22:34 ` [BlueZ] " bluez.test.bot
  2022-03-31 18:30 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Inga Stotland @ 2022-03-30 21:17 UTC (permalink / raw)
  To: brian.gix, linux-bluetooth; +Cc: Inga Stotland

This addresses a situation when a boolean type is represented by
an integer and performing a left shift on a boolean causes
an integer overflow.

This fixes the following runtime error:
"left shift of 1 by 31 places cannot be represented in type 'int'"
---
 mesh/crypto.c |  5 ++++-
 mesh/net.c    | 12 ++++++------
 mesh/net.h    |  8 ++++----
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/mesh/crypto.c b/mesh/crypto.c
index da227ebbb..668d16877 100644
--- a/mesh/crypto.c
+++ b/mesh/crypto.c
@@ -553,8 +553,11 @@ bool mesh_crypto_packet_build(bool ctl, uint8_t ttl,
 	n = 9;
 
 	if (!ctl) {
-		hdr = segmented << SEG_HDR_SHIFT;
+		uint32_t tmp = segmented ? 0x1 : 0;
+
+		hdr = tmp << SEG_HDR_SHIFT;
 		hdr |= (key_aid & KEY_ID_MASK) << KEY_HDR_SHIFT;
+
 		if (segmented) {
 			hdr |= szmic << SZMIC_HDR_SHIFT;
 			hdr |= (seqZero & SEQ_ZERO_MASK) << SEQ_ZERO_HDR_SHIFT;
diff --git a/mesh/net.c b/mesh/net.c
index df82b2655..8ff3ef32e 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -1375,7 +1375,7 @@ static void friend_ack_rxed(struct mesh_net *net, uint32_t iv_index,
 {
 	uint32_t hdr = l_get_be32(pkt) &
 		((SEQ_ZERO_MASK << SEQ_ZERO_HDR_SHIFT) | /* Preserve SeqZero */
-		 (true << RELAY_HDR_SHIFT));		/* Preserve Relay bit */
+		 ((uint32_t) 0x01 << RELAY_HDR_SHIFT)); /* Preserve Relay bit */
 	uint32_t flags = l_get_be32(pkt + 3);
 	struct mesh_friend_msg frnd_ack = {
 		.ctl = true,
@@ -1410,14 +1410,14 @@ static void send_frnd_ack(struct mesh_net *net, uint16_t src, uint16_t dst,
 	expected = 0xffffffff >> (31 - SEG_TOTAL(hdr));
 
 	/* Clear Hdr bits that don't apply to Seg ACK */
-	hdr &= ~((true << SEG_HDR_SHIFT) |
+	hdr &= ~(((uint32_t) 0x01 << SEG_HDR_SHIFT) |
 			(OPCODE_MASK << OPCODE_HDR_SHIFT) |
-			(true << SZMIC_HDR_SHIFT) |
+			((uint32_t) 0x01 << SZMIC_HDR_SHIFT) |
 			(SEG_MASK << SEGO_HDR_SHIFT) |
 			(SEG_MASK << SEGN_HDR_SHIFT));
 
 	hdr |= NET_OP_SEG_ACKNOWLEDGE << OPCODE_HDR_SHIFT;
-	hdr |= true << RELAY_HDR_SHIFT;
+	hdr |= (uint32_t) 0x01 << RELAY_HDR_SHIFT;
 
 	/* Clear all unexpected bits */
 	flags &= expected;
@@ -1454,7 +1454,7 @@ static void send_net_ack(struct mesh_net *net, struct mesh_sar *sar,
 	hdr |= sar->seqZero << SEQ_ZERO_HDR_SHIFT;
 
 	if (is_lpn_friend(net, src))
-		hdr |= true << RELAY_HDR_SHIFT;
+		hdr |= (uint32_t) 0x01 << RELAY_HDR_SHIFT;
 
 	l_put_be32(hdr, msg);
 	l_put_be32(flags, msg + 3);
@@ -1726,7 +1726,7 @@ static bool msg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
 		}
 
 		if (szmic || size > 15) {
-			hdr |= true << SEG_HDR_SHIFT;
+			hdr |= (uint32_t) 0x01 << SEG_HDR_SHIFT;
 			hdr |= szmic << SZMIC_HDR_SHIFT;
 			hdr |= (seqZero & SEQ_ZERO_MASK) << SEQ_ZERO_HDR_SHIFT;
 			hdr |= SEG_MAX(true, size) << SEGN_HDR_SHIFT;
diff --git a/mesh/net.h b/mesh/net.h
index 1c2b5e7c6..0bacbbbbf 100644
--- a/mesh/net.h
+++ b/mesh/net.h
@@ -37,7 +37,7 @@ struct mesh_node;
 #define SEGMENTED	0x80
 #define UNSEGMENTED	0x00
 #define SEG_HDR_SHIFT	31
-#define IS_SEGMENTED(hdr)	(!!((hdr) & (true << SEG_HDR_SHIFT)))
+#define IS_SEGMENTED(hdr)	(!!((hdr) & ((uint32_t) 0x1 << SEG_HDR_SHIFT)))
 
 #define KEY_ID_MASK	0x7f
 #define KEY_AID_MASK	0x3f
@@ -45,7 +45,7 @@ struct mesh_node;
 #define KEY_AID_SHIFT	0
 #define AKF_HDR_SHIFT	30
 #define KEY_HDR_SHIFT	24
-#define HAS_APP_KEY(hdr)	(!!((hdr) & (true << AKF_HDR_SHIFT)))
+#define HAS_APP_KEY(hdr)	(!!((hdr) & ((uint32_t) 0x1 << AKF_HDR_SHIFT)))
 
 #define OPCODE_MASK	0x7f
 #define OPCODE_HDR_SHIFT	24
@@ -55,8 +55,8 @@ struct mesh_node;
 #define SZMIC_HDR_SHIFT	23
 #define SEQ_ZERO_MASK	0x1fff
 #define SEQ_ZERO_HDR_SHIFT	10
-#define IS_RELAYED(hdr)	(!!((hdr) & (true << RELAY_HDR_SHIFT)))
-#define HAS_MIC64(hdr)	(!!((hdr) & (true << SZMIC_HDR_SHIFT)))
+#define IS_RELAYED(hdr)	(!!((hdr) & ((uint32_t) 0x1 << RELAY_HDR_SHIFT)))
+#define HAS_MIC64(hdr)	(!!((hdr) & ((uint32_t) 0x1 << SZMIC_HDR_SHIFT)))
 
 #define SEG_MASK	0x1f
 #define SEGO_HDR_SHIFT	5
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [BlueZ] mesh: use explicit uint32_t when bit shifting left
  2022-03-30 21:17 [PATCH BlueZ] mesh: use explicit uint32_t when bit shifting left Inga Stotland
@ 2022-03-30 22:34 ` bluez.test.bot
  2022-03-31 18:30 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2022-03-30 22:34 UTC (permalink / raw)
  To: linux-bluetooth, inga.stotland

[-- Attachment #1: Type: text/plain, Size: 995 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=627632

---Test result---

Test Summary:
CheckPatch                    PASS      1.52 seconds
GitLint                       PASS      0.99 seconds
Prep - Setup ELL              PASS      41.73 seconds
Build - Prep                  PASS      0.75 seconds
Build - Configure             PASS      8.53 seconds
Build - Make                  PASS      1190.18 seconds
Make Check                    PASS      11.58 seconds
Make Check w/Valgrind         PASS      416.72 seconds
Make Distcheck                PASS      217.35 seconds
Build w/ext ELL - Configure   PASS      8.28 seconds
Build w/ext ELL - Make        PASS      1186.12 seconds
Incremental Build with patchesPASS      0.00 seconds



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ] mesh: use explicit uint32_t when bit shifting left
  2022-03-30 21:17 [PATCH BlueZ] mesh: use explicit uint32_t when bit shifting left Inga Stotland
  2022-03-30 22:34 ` [BlueZ] " bluez.test.bot
@ 2022-03-31 18:30 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2022-03-31 18:30 UTC (permalink / raw)
  To: Inga Stotland; +Cc: brian.gix, linux-bluetooth

Hello:

This patch was applied to bluetooth/bluez.git (master)
by Brian Gix <brian.gix@intel.com>:

On Wed, 30 Mar 2022 14:17:47 -0700 you wrote:
> This addresses a situation when a boolean type is represented by
> an integer and performing a left shift on a boolean causes
> an integer overflow.
> 
> This fixes the following runtime error:
> "left shift of 1 by 31 places cannot be represented in type 'int'"
> 
> [...]

Here is the summary with links:
  - [BlueZ] mesh: use explicit uint32_t when bit shifting left
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ff35b1d2e97e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-31 18:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30 21:17 [PATCH BlueZ] mesh: use explicit uint32_t when bit shifting left Inga Stotland
2022-03-30 22:34 ` [BlueZ] " bluez.test.bot
2022-03-31 18:30 ` [PATCH BlueZ] " patchwork-bot+bluetooth

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