Skip to contentSkip to conversation

bt: avoid unintended sign extension

PATCH Applied Paolo Bonzini 3 participants 3 messages Nov 27, 2015 – Nov 29, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bt: avoid unintended sign extension

In the case of a 4-byte length, shifting a value by 24 may cause an unintended sign extension when converting from int to size_t. Use a uint32_t variable instead.

---
 hw/bt/sdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/bt/sdp.c +1 -1
index b9bcdcc..04eaeca 100644
@@ -42,7 +42,7 @@ struct bt_l2cap_sdp_state_s {
 
 static ssize_t sdp_datalen(const uint8_t **element, ssize_t *left)
 {
-    size_t len = *(*element) ++ & SDP_DSIZE_MASK;
+    uint32_t len = *(*element) ++ & SDP_DSIZE_MASK;
 
     if (!*left)
         return -1;
Signature · 1 line
2.5.0
#2 lore raw
In reply to Paolo Bonzini
Quoted 3 lines · Paolo Bonzini

In the case of a 4-byte length, shifting a value by 24 may cause an unintended sign extension when converting from int to size_t. Use a uint32_t variable instead.

Applied to -trivial, thank you!

/mjt