Fix inet_aton on LP32.
I wasn't checking for overflow. Luckily, I had a test that overflows on LP32.
Change-Id: If2cf33d88f459eb26d0ce75f3c5ed192f516ab7a
diff --git a/libc/bionic/arpa_inet.cpp b/libc/bionic/arpa_inet.cpp
index 260d6a0..9d4afe3 100644
--- a/libc/bionic/arpa_inet.cpp
+++ b/libc/bionic/arpa_inet.cpp
@@ -39,8 +39,9 @@
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;
}
diff --git a/tests/arpa_inet_test.cpp b/tests/arpa_inet_test.cpp
index 8ba0d7a..a368b8f 100644
--- a/tests/arpa_inet_test.cpp
+++ b/tests/arpa_inet_test.cpp
@@ -98,7 +98,11 @@
// 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) {