mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Fix inet_ntop(AF_INET6) buffer length (#582)
This commit is contained in:
parent
12212894eb
commit
494d74271b
2 changed files with 8 additions and 8 deletions
|
@ -27,7 +27,7 @@
|
||||||
* @param af can be AF_INET or AF_INET6
|
* @param af can be AF_INET or AF_INET6
|
||||||
* @param src is the binary-encoded address, e.g. &addr->sin_addr
|
* @param src is the binary-encoded address, e.g. &addr->sin_addr
|
||||||
* @param dst is the output string buffer
|
* @param dst is the output string buffer
|
||||||
* @param size needs to be 16+ for IPv4 and 72+ for IPv6
|
* @param size needs to be 16+ for IPv4 and 46+ for IPv6
|
||||||
* @return dst on success or NULL w/ errno
|
* @return dst on success or NULL w/ errno
|
||||||
*/
|
*/
|
||||||
const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) {
|
const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) {
|
||||||
|
@ -52,7 +52,7 @@ const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) {
|
||||||
enospc();
|
enospc();
|
||||||
}
|
}
|
||||||
} else if (af == AF_INET6) {
|
} else if (af == AF_INET6) {
|
||||||
if (size >= 16 * 4 + 8) {
|
if (size >= 46) {
|
||||||
t = 0;
|
t = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
for (i = 0; i < 16; i += 2) {
|
for (i = 0; i < 16; i += 2) {
|
||||||
|
|
|
@ -56,14 +56,14 @@ TEST(inet_ntop, testNoSpace) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(inet_ntop, ipv6_testMin_isJustColons) {
|
TEST(inet_ntop, ipv6_testMin_isJustColons) {
|
||||||
char buf[72];
|
char buf[46];
|
||||||
uint8_t ip[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
uint8_t ip[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
EXPECT_STREQ("::", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
EXPECT_STREQ("::", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(inet_ntop, ipv6_testMax) {
|
TEST(inet_ntop, ipv6_testMax) {
|
||||||
char buf[72];
|
char buf[46];
|
||||||
uint8_t ip[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
uint8_t ip[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||||
EXPECT_STREQ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
|
EXPECT_STREQ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
|
||||||
|
@ -71,14 +71,14 @@ TEST(inet_ntop, ipv6_testMax) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(inet_ntop, ipv6_loopback_isColonsThenJustOne) {
|
TEST(inet_ntop, ipv6_loopback_isColonsThenJustOne) {
|
||||||
char buf[72];
|
char buf[46];
|
||||||
uint8_t ip[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
uint8_t ip[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
|
||||||
EXPECT_STREQ("::1", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
EXPECT_STREQ("::1", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(inet_ntop, ipv6_rfc4291example) {
|
TEST(inet_ntop, ipv6_rfc4291example) {
|
||||||
char buf[72];
|
char buf[46];
|
||||||
uint8_t ip[16] = {0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
|
uint8_t ip[16] = {0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x08, 0x08, 0x00, 0x20, 0x0C, 0x41, 0x7A};
|
0x00, 0x08, 0x08, 0x00, 0x20, 0x0C, 0x41, 0x7A};
|
||||||
EXPECT_STREQ("2001:db8::8:800:200c:417a",
|
EXPECT_STREQ("2001:db8::8:800:200c:417a",
|
||||||
|
@ -86,14 +86,14 @@ TEST(inet_ntop, ipv6_rfc4291example) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(inet_ntop, ipv6_leading) {
|
TEST(inet_ntop, ipv6_leading) {
|
||||||
char buf[72];
|
char buf[46];
|
||||||
uint8_t ip[16] = {0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
uint8_t ip[16] = {0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
EXPECT_STREQ("1::", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
EXPECT_STREQ("1::", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(inet_ntop, ipv6_kindOfLeading) {
|
TEST(inet_ntop, ipv6_kindOfLeading) {
|
||||||
char buf[72];
|
char buf[46];
|
||||||
uint8_t ip[16] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
uint8_t ip[16] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
EXPECT_STREQ("100::", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
EXPECT_STREQ("100::", inet_ntop(AF_INET6, ip, buf, sizeof(buf)));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue