diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2024-01-30 17:29:55 -0500 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2024-01-30 17:29:55 -0500 |
commit | f071eb5a4b11bcb21a13c62acff93603d1581ebb (patch) | |
tree | f797780e502f6ce4bcf8a4be707cafe83550bb34 | |
parent | 332419ea0875359672d3aab5cbb47dbaf9392639 (diff) |
interfaces: Avoid using strncpy to keep NULL termination
-rw-r--r-- | agent/interfaces.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/agent/interfaces.c b/agent/interfaces.c index dea604f..27fdaf0 100644 --- a/agent/interfaces.c +++ b/agent/interfaces.c @@ -275,7 +275,7 @@ get_local_ips_ioctl (gboolean include_loopback) continue; memset (&ifr2, 0, sizeof (ifr2)); - strncpy (ifr2.ifr_name, ifr->ifr_name, IFNAMSIZ); + g_strlcpy (ifr2.ifr_name, ifr->ifr_name, IFNAMSIZ); if (ioctl (sockfd, SIOCGIFFLAGS, &ifr2)) { nice_debug ( "Error : Unable to get IP flags information for interface %s." @@ -382,7 +382,7 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr) continue; memset (&ifr2, 0, sizeof (struct ifreq)); - strncpy (ifr2.ifr_name, ifr->ifr_name, IFNAMSIZ); + g_strlcpy (ifr2.ifr_name, ifr->ifr_name, IFNAMSIZ); if (ioctl (sockfd, SIOCGIFINDEX, &ifr2)) { nice_debug ("Error : Unable to get IP address information for interface %s." @@ -617,7 +617,7 @@ nice_interfaces_get_ip_for_interface (gchar *interface_name) g_return_val_if_fail (interface_name != NULL, NULL); memset (&ifr, 0, sizeof (struct ifreq)); - strncpy (ifr.ifr_name, interface_name, sizeof (ifr.ifr_name)); + g_strlcpy (ifr.ifr_name, interface_name, IFNAMSIZ); if ((sockfd = socket (AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) { nice_debug ("Error : Cannot open socket to retrieve interface list"); |