DHCPClient: Prefer strlcpy over strncpy, fixes off-by-one

A malicious caller of set_params could have caused the ifr_name field to
lack NUL-termination. I don't think this was an actual problem, though, as
the Kernel always forces NUL-termination by overwriting ifr_name's last byte
with NUL.

However, it feels better to do it properly.

No behaviour change (probably).
This commit is contained in:
Ben Wiederhake 2020-08-23 13:34:58 +02:00 committed by Andreas Kling
parent e682967d7e
commit 46b04a79e5
Notes: sideshowbarker 2024-07-19 03:14:15 +09:00

View file

@ -70,7 +70,7 @@ static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, iface.m_ifname.characters(), IFNAMSIZ);
strlcpy(ifr.ifr_name, iface.m_ifname.characters(), IFNAMSIZ);
// set the IP address
ifr.ifr_addr.sa_family = AF_INET;