mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
Userland: Prefer strlcpy over strncpy in ifconfig, fixes off-by-one
A malicious caller of ifconfig 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.
This commit is contained in:
parent
46b04a79e5
commit
5c1a72f0ef
1 changed files with 2 additions and 2 deletions
|
@ -116,7 +116,7 @@ int main(int argc, char** argv)
|
|||
struct ifreq ifr;
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
|
||||
strncpy(ifr.ifr_name, ifname.characters(), IFNAMSIZ);
|
||||
strlcpy(ifr.ifr_name, ifname.characters(), IFNAMSIZ);
|
||||
ifr.ifr_addr.sa_family = AF_INET;
|
||||
((sockaddr_in&)ifr.ifr_addr).sin_addr.s_addr = address.value().to_in_addr_t();
|
||||
|
||||
|
@ -144,7 +144,7 @@ int main(int argc, char** argv)
|
|||
struct ifreq ifr;
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
|
||||
strncpy(ifr.ifr_name, ifname.characters(), IFNAMSIZ);
|
||||
strlcpy(ifr.ifr_name, ifname.characters(), IFNAMSIZ);
|
||||
ifr.ifr_netmask.sa_family = AF_INET;
|
||||
((sockaddr_in&)ifr.ifr_netmask).sin_addr.s_addr = address.value().to_in_addr_t();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue