Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: mdns_responder: Use memcpy instead of strncpy for iface name #87348

Merged

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Mar 19, 2025

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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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 <jukka.rissanen@nordicsemi.no>
@jukkar jukkar force-pushed the fix/mdns-responder-ifname-copy branch from 040e6d3 to 63bdddb Compare March 20, 2025 06:24
@jukkar
Copy link
Member Author

jukkar commented Mar 20, 2025

  • Rebased to latest main hoping it resolves the unrelated CI error

@kartben kartben merged commit cc282e5 into zephyrproject-rtos:main Mar 21, 2025
22 checks passed
@jukkar jukkar deleted the fix/mdns-responder-ifname-copy branch March 23, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants