Skip to content

Commit 31b79a9

Browse files
rlubosdanieldegrasse
authored andcommitted
net: pkt: Add explicit casts to uint32_t when bitshifting uint8_t val
Cast uint8_t variable to uint32_t explicitly to avoid implicit cast to int, and thus potentially undefined behavior, reported by UBSAN: net_pkt.c:1946:17: runtime error: left shift of 239 by 24 places cannot be represented in type 'int' Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 7949789 commit 31b79a9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

subsys/net/ip/net_pkt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,8 @@ int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data)
19431943

19441944
ret = net_pkt_read(pkt, d32, sizeof(uint32_t));
19451945

1946-
*data = d32[0] << 24 | d32[1] << 16 | d32[2] << 8 | d32[3];
1946+
*data = (uint32_t)d32[0] << 24 | (uint32_t)d32[1] << 16 |
1947+
(uint32_t)d32[2] << 8 | (uint32_t)d32[3];
19471948

19481949
return ret;
19491950
}

0 commit comments

Comments
 (0)