Skip to content

Commit cc282e5

Browse files
jukkarkartben
authored andcommitted
net: mdns_responder: Use memcpy instead of strncpy for iface name
Following warning is printed if using strncpy(), so use memcpy() instead. Note that this is false positive as there is no error here but in order to avoid the warning, change the copy function. subsys/net/lib/dns/mdns_responder.c:1371:25: warning: 'strncpy' output may be truncated copying 7 bytes from a string of length 8 [-Wstringop-truncation] 1468 | strncpy(if_req.ifr_name, name, sizeof(if_req.ifr_name) - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ subsys/net/lib/dns/mdns_responder.c:1468:25: warning: 'strncpy' output may be truncated copying 7 bytes from a string of length 8 [-Wstringop-truncation] 1468 | strncpy(if_req.ifr_name, name, sizeof(if_req.ifr_name) - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 1e75b82 commit cc282e5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

subsys/net/lib/dns/mdns_responder.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,8 @@ static int init_listener(void)
13681368
ifindex, ret);
13691369
} else {
13701370
memset(&if_req, 0, sizeof(if_req));
1371-
strncpy(if_req.ifr_name, name, sizeof(if_req.ifr_name) - 1);
1371+
memcpy(if_req.ifr_name, name,
1372+
MIN(sizeof(name) - 1, sizeof(if_req.ifr_name) - 1));
13721373

13731374
ret = zsock_setsockopt(v6, SOL_SOCKET, SO_BINDTODEVICE,
13741375
&if_req, sizeof(if_req));
@@ -1464,7 +1465,8 @@ static int init_listener(void)
14641465
ifindex, ret);
14651466
} else {
14661467
memset(&if_req, 0, sizeof(if_req));
1467-
strncpy(if_req.ifr_name, name, sizeof(if_req.ifr_name) - 1);
1468+
memcpy(if_req.ifr_name, name,
1469+
MIN(sizeof(name) - 1, sizeof(if_req.ifr_name) - 1));
14681470

14691471
ret = zsock_setsockopt(v4, SOL_SOCKET, SO_BINDTODEVICE,
14701472
&if_req, sizeof(if_req));

0 commit comments

Comments
 (0)