Pull in upstream fixes to reject invalid bases.

Also add tests to make sure the full set works correctly.

Change-Id: I3e7f237f12c9c93e1185a97c9717803e7e55a73c
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 553f018..667ccd6 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -361,3 +361,51 @@
   ASSERT_EQ(ENOTTY, errno);
   close(fd);
 }
+
+TEST(stdlib, strtol_EINVAL) {
+  errno = 0;
+  strtol("123", NULL, -1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtol("123", NULL, 1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtol("123", NULL, 37);
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(stdlib, strtoll_EINVAL) {
+  errno = 0;
+  strtoll("123", NULL, -1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtoll("123", NULL, 1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtoll("123", NULL, 37);
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(stdlib, strtoul_EINVAL) {
+  errno = 0;
+  strtoul("123", NULL, -1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtoul("123", NULL, 1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtoul("123", NULL, 37);
+  ASSERT_EQ(EINVAL, errno);
+}
+
+TEST(stdlib, strtoull_EINVAL) {
+  errno = 0;
+  strtoull("123", NULL, -1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtoull("123", NULL, 1);
+  ASSERT_EQ(EINVAL, errno);
+  errno = 0;
+  strtoull("123", NULL, 37);
+  ASSERT_EQ(EINVAL, errno);
+}