aboutsummaryrefslogtreecommitdiff
path: root/resolv/inet_addr.c
diff options
context:
space:
mode:
Diffstat (limited to 'resolv/inet_addr.c')
-rw-r--r--resolv/inet_addr.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/resolv/inet_addr.c b/resolv/inet_addr.c
index a5667eb6ed..fe15b5701b 100644
--- a/resolv/inet_addr.c
+++ b/resolv/inet_addr.c
@@ -99,6 +99,7 @@ inet_aton(cp, addr)
const char *cp;
struct in_addr *addr;
{
+ static const u_int32_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff };
register u_int32_t val; /* changed from u_long --david */
#ifndef _LIBC
register int base;
@@ -113,6 +114,8 @@ inet_aton(cp, addr)
__set_errno (0);
#endif
+ memset (parts, '\0', sizeof (parts));
+
c = *cp;
for (;;) {
/*
@@ -178,33 +181,14 @@ inet_aton(cp, addr)
* the number of parts specified.
*/
n = pp - parts + 1;
- switch (n) {
-
- case 0:
- goto ret_0; /* initial nondigit */
- case 1: /* a -- 32 bits */
- break;
+ if (n == 0 /* initial nondigit */
+ || parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff
+ || val > max[n - 1])
+ goto ret_0;
- case 2: /* a.b -- 8.24 bits */
- if (parts[0] > 0xff || val > 0xffffff)
- goto ret_0;
- val |= parts[0] << 24;
- break;
+ val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
- case 3: /* a.b.c -- 8.8.16 bits */
- if (parts[0] > 0xff || parts[1] > 0xff || val > 0xffff)
- goto ret_0;
- val |= (parts[0] << 24) | (parts[1] << 16);
- break;
-
- case 4: /* a.b.c.d -- 8.8.8.8 bits */
- if (parts[0] > 0xff || parts[1] > 0xff || parts[2] > 0xff
- || val > 0xff)
- goto ret_0;
- val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
- break;
- }
if (addr)
addr->s_addr = htonl(val);