diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2020-08-16 18:18:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-22 20:55:10 +0200 |
commit | 4f77ccbda81b6721992dcc93958ef1ae9b20066f (patch) | |
tree | 99281ee652a02d2fb0d95c70518b4b6d5d9ccd57 /Libraries/LibC | |
parent | 1aad0f8b16f886eedb99434eb9010dda4f0a0522 (diff) | |
download | serenity-4f77ccbda81b6721992dcc93958ef1ae9b20066f.zip |
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.
Diffstat (limited to 'Libraries/LibC')
-rw-r--r-- | Libraries/LibC/netdb.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Libraries/LibC/netdb.cpp b/Libraries/LibC/netdb.cpp index 409e068da9..ed1799205a 100644 --- a/Libraries/LibC/netdb.cpp +++ b/Libraries/LibC/netdb.cpp @@ -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; |