mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibC: Validate the len argument for inet_ntop()
This commit is contained in:
parent
bffa1a0df8
commit
287a93a2a4
1 changed files with 4 additions and 0 deletions
|
@ -37,6 +37,10 @@ const char* inet_ntop(int af, const void* src, char* dst, socklen_t len)
|
||||||
errno = EAFNOSUPPORT;
|
errno = EAFNOSUPPORT;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (len < 4) {
|
||||||
|
errno = ENOSPC;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
auto* bytes = (const unsigned char*)src;
|
auto* bytes = (const unsigned char*)src;
|
||||||
snprintf(dst, len, "%u.%u.%u.%u", bytes[0], bytes[1], bytes[2], bytes[3]);
|
snprintf(dst, len, "%u.%u.%u.%u", bytes[0], bytes[1], bytes[2], bytes[3]);
|
||||||
return (const char*)dst;
|
return (const char*)dst;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue