summaryrefslogtreecommitdiff
path: root/mesh
diff options
context:
space:
mode:
authorInga Stotland <inga.stotland@intel.com>2022-03-30 14:17:47 -0700
committerBrian Gix <brian.gix@intel.com>2022-03-31 11:21:56 -0700
commitff35b1d2e97e68f67cc556f85005636b65a190cb (patch)
tree28c4a5e722f7f53d381af324fa4186e57df5dce0 /mesh
parent4a06a31be0453d7c8208108dccbb7cfacf768bc4 (diff)
downloadbluez-ff35b1d2e97e68f67cc556f85005636b65a190cb.tar.gz
mesh: use explicit uint32_t when bit shifting left
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'"
Diffstat (limited to 'mesh')
-rw-r--r--mesh/crypto.c5
-rw-r--r--mesh/net.c12
-rw-r--r--mesh/net.h8
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