Skip to content

Commit 8b91d3a

Browse files
rluboskartben
authored andcommitted
net: websocket: Fix truncated string warning on copying
WS_MAGIC is a constant string and when calculating lengths for copying we always exclude the NULL terminator. In result, using strncpy() for copying can generate a warning about truncated string, as WS_MAGIC will always be truncated from the NULL terminator. Therefore replace strncpy() with memcpy() as it seems more appropriate for this case. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent dda100c commit 8b91d3a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

subsys/net/lib/websocket/websocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ int websocket_connect(int sock, struct websocket_request *wreq,
365365
key_len);
366366

367367
olen = MIN(sizeof(key_accept) - 1 - key_len, sizeof(WS_MAGIC) - 1);
368-
strncpy(key_accept + key_len, WS_MAGIC, olen);
368+
memcpy(key_accept + key_len, WS_MAGIC, olen);
369369

370370
/* This SHA-1 value is then checked when we receive the response */
371371
#ifdef CONFIG_MBEDTLS_PSA_CRYPTO_CLIENT

0 commit comments

Comments
 (0)