Ver Fonte

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).
Ben Wiederhake há 4 anos atrás
pai
commit
46b04a79e5
1 ficheiros alterados com 1 adições e 1 exclusões
  1. 1 1
      Services/DHCPClient/DHCPv4Client.cpp

+ 1 - 1
Services/DHCPClient/DHCPv4Client.cpp

@@ -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;