Fix inet_aton on LP32.
I wasn't checking for overflow. Luckily, I had a test that overflows on LP32. Change-Id: If2cf33d88f459eb26d0ce75f3c5ed192f516ab7a
This commit is contained in:
parent
487a1823e8
commit
7b77cb35af
2 changed files with 7 additions and 2 deletions
|
@ -39,8 +39,9 @@ int inet_aton(const char* cp, in_addr* addr) {
|
|||
size_t i;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
char* end;
|
||||
errno = 0;
|
||||
parts[i] = strtoul(cp, &end, 0);
|
||||
if (end == cp || (*end != '.' && *end != '\0')) return 0;
|
||||
if (errno != 0 || end == cp || (*end != '.' && *end != '\0')) return 0;
|
||||
if (*end == '\0') break;
|
||||
cp = end + 1;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,11 @@ TEST(arpa_inet, inet_aton_invalid) {
|
|||
// Out of range a form.
|
||||
ASSERT_EQ(0, inet_aton("0x100000000", nullptr));
|
||||
|
||||
ASSERT_EQ(0, inet_aton("0400.0.0.1", nullptr)); // Out of range octal.
|
||||
// 64-bit overflow.
|
||||
ASSERT_EQ(0, inet_aton("0x10000000000000000", nullptr));
|
||||
|
||||
// Out of range octal.
|
||||
ASSERT_EQ(0, inet_aton("0400.0.0.1", nullptr));
|
||||
}
|
||||
|
||||
TEST(arpa_inet, inet_lnaof) {
|
||||
|
|
Loading…
Reference in a new issue