LibC: Validate the len argument for inet_ntop()

This commit is contained in:
Gunnar Beutner 2021-04-12 16:44:04 +02:00 committed by Andreas Kling
commit 287a93a2a4
Notes: sideshowbarker 2024-07-18 20:27:10 +09:00

View file

@ -37,6 +37,10 @@ const char* inet_ntop(int af, const void* src, char* dst, socklen_t len)
errno = EAFNOSUPPORT;
return nullptr;
}
if (len < 4) {
errno = ENOSPC;
return nullptr;
}
auto* bytes = (const unsigned char*)src;
snprintf(dst, len, "%u.%u.%u.%u", bytes[0], bytes[1], bytes[2], bytes[3]);
return (const char*)dst;