1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

LibC+Userland: Prefer snprintf over sprintf

I ignored the sprintf in Userland/cal.cpp because it's too much trouble.
However, this only underlines the need for bounds checking.
This commit is contained in:
Ben Wiederhake 2020-08-16 18:18:07 +02:00 committed by Andreas Kling
parent 1aad0f8b16
commit 4f77ccbda8
2 changed files with 7 additions and 3 deletions

View file

@ -100,7 +100,9 @@ hostent* gethostbyname(const char* name)
{
auto ipv4_address = IPv4Address::from_string(name);
if (ipv4_address.has_value()) {
sprintf(__gethostbyname_name_buffer, "%s", ipv4_address.value().to_string().characters());
auto ip4_string = ipv4_address.value().to_string();
ASSERT(ip4_string.length() < sizeof(__gethostbyname_name_buffer));
strncpy(__gethostbyname_name_buffer, ip4_string.characters(), ip4_string.length());
__gethostbyname_buffer.h_name = __gethostbyname_name_buffer;
__gethostbyname_buffer.h_aliases = nullptr;
__gethostbyname_buffer.h_addrtype = AF_INET;