Skip to content

Commit bd96b5d

Browse files
rlubosdanieldegrasse
authored andcommitted
net: lib: websocket: Avoid bitshift overflow warning
In order to prevent an overflow warning from UBSAN when bitshifting, cast to uint64_t first before shifting, and then back to uint32_t. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent c7757b9 commit bd96b5d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

subsys/net/lib/websocket/websocket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ static int websocket_parse(struct websocket_context *ctx, struct websocket_buffe
842842
break;
843843
case WEBSOCKET_PARSER_STATE_MASK:
844844
ctx->parser_remaining--;
845-
ctx->masking_value |= (data << (ctx->parser_remaining * 8));
845+
ctx->masking_value |=
846+
(uint32_t)((uint64_t)data << (ctx->parser_remaining * 8));
846847
if (ctx->parser_remaining == 0) {
847848
if (ctx->message_len == 0) {
848849
ctx->parser_remaining = 0;

0 commit comments

Comments
 (0)