about summary refs log tree commit diff
path: root/resolv
diff options
context:
space:
mode:
Diffstat (limited to 'resolv')
-rw-r--r--resolv/Makefile1
-rw-r--r--resolv/inet_addr.c2
-rw-r--r--resolv/tst-inet_addr-binary.c30
3 files changed, 32 insertions, 1 deletions
diff --git a/resolv/Makefile b/resolv/Makefile
index cc69b4e60b..5128bd0bc1 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -88,6 +88,7 @@ routines += gai_sigqueue
 tests += \
   tst-bug18665 \
   tst-bug18665-tcp \
+  tst-inet_addr-binary \
   tst-ns_name \
   tst-ns_name_compress \
   tst-ns_name_pton \
diff --git a/resolv/inet_addr.c b/resolv/inet_addr.c
index 136792ebfa..9bb67594e5 100644
--- a/resolv/inet_addr.c
+++ b/resolv/inet_addr.c
@@ -130,7 +130,7 @@ inet_aton_end (const char *cp, struct in_addr *addr, const char **endp)
 	goto ret_0;
       {
 	char *endp;
-	unsigned long ul = strtoul (cp, &endp, 0);
+	unsigned long ul = __strtoul_internal (cp, &endp, 0, 0);
 	if (ul == ULONG_MAX && errno == ERANGE)
 	  goto ret_0;
 	if (ul > 0xfffffffful)
diff --git a/resolv/tst-inet_addr-binary.c b/resolv/tst-inet_addr-binary.c
new file mode 100644
index 0000000000..14a7152567
--- /dev/null
+++ b/resolv/tst-inet_addr-binary.c
@@ -0,0 +1,30 @@
+/* Test inet_addr does not accept C2X binary constants.
+   Copyright (C) 2022-2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <arpa/inet.h>
+
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  TEST_COMPARE (inet_addr ("0b101"), (in_addr_t) -1);
+  return 0;
+}
+
+#include <support/test-driver.c>