You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Marc Slemko <ma...@znep.com> on 1997/11/14 04:30:24 UTC

[PATCH] fix strtoul

Index: proxy_util.c
===================================================================
RCS file: /export/home/cvs/apachen/src/modules/proxy/proxy_util.c,v
retrieving revision 1.35
diff -u -r1.35 proxy_util.c
--- proxy_util.c	1997/11/01 21:13:24	1.35
+++ proxy_util.c	1997/11/14 03:23:16
@@ -867,9 +867,9 @@
 int proxy_is_ipaddr(struct dirconn_entry *This)
 {
     const char *addr = This->name;
-    unsigned long ip_addr[4];
+    long ip_addr[4];
     int i, quads;
-    unsigned long bits;
+    long bits;
 
     /* if the address is given with an explicit netmask, use that */
     /* Due to a deficiency in ap_inet_addr(), it is impossible to parse */
@@ -900,11 +900,16 @@
 	if (!isdigit(*addr))
 	    return 0;		/* no digit at start of quad */
 
-	ip_addr[quads] = strtoul(addr, &tmp, 0);
+	ip_addr[quads] = strtol(addr, &tmp, 0);
 
 	if (tmp == addr)	/* expected a digit, found something else */
 	    return 0;
 
+	if (ip_addr[quads] < 0 || ip_addr[quads] > 255) {
+	    /* invalid octet */
+	    return 0;
+	}
+
 	addr = tmp;
 
 	if (*addr == '.' && quads != 3)
@@ -919,14 +924,14 @@
 
 	++addr;
 
-	bits = strtoul(addr, &tmp, 0);
+	bits = strtol(addr, &tmp, 0);
 
 	if (tmp == addr)	/* expected a digit, found something else */
 	    return 0;
 
 	addr = tmp;
 
-	if (bits > 32)		/* netmask must be between 0 and 32 */
+	if (bits < 0 || bits > 32)	/* netmask must be between 0 and 32 */
 	    return 0;
 
     }


Re: [PATCH] fix strtoul

Posted by Martin Kraemer <Ma...@mch.sni.de>.
On Fri, Nov 14, 1997 at 01:12:22AM -0800, Dean Gaudet wrote:
> +1
> 
> [Dean wonders if this code looks similar to parsing code in mod_access...
> and thinks a nice library function is hidden in it somewhere :]

Yep. But mod_proxy had it way _before_ mod_access ;-)
I needed the code, no global routine was available, so I wrote it...

+1 as well.


    Martin
-- 
| S I E M E N S |  <Ma...@mch.sni.de>  |      Siemens Nixdorf
| ------------- |   Voice: +49-89-636-46021     |  Informationssysteme AG
| N I X D O R F |   FAX:   +49-89-636-44994     |   81730 Munich, Germany
~~~~~~~~~~~~~~~~My opinions only, of course; pgp key available on request

Re: [PATCH] fix strtoul

Posted by Dean Gaudet <dg...@arctic.org>.
+1

[Dean wonders if this code looks similar to parsing code in mod_access...
and thinks a nice library function is hidden in it somewhere :]

Dean

On Thu, 13 Nov 1997, Marc Slemko wrote:

> Index: proxy_util.c
> ===================================================================
> RCS file: /export/home/cvs/apachen/src/modules/proxy/proxy_util.c,v
> retrieving revision 1.35
> diff -u -r1.35 proxy_util.c
> --- proxy_util.c	1997/11/01 21:13:24	1.35
> +++ proxy_util.c	1997/11/14 03:23:16
> @@ -867,9 +867,9 @@
>  int proxy_is_ipaddr(struct dirconn_entry *This)
>  {
>      const char *addr = This->name;
> -    unsigned long ip_addr[4];
> +    long ip_addr[4];
>      int i, quads;
> -    unsigned long bits;
> +    long bits;
>  
>      /* if the address is given with an explicit netmask, use that */
>      /* Due to a deficiency in ap_inet_addr(), it is impossible to parse */
> @@ -900,11 +900,16 @@
>  	if (!isdigit(*addr))
>  	    return 0;		/* no digit at start of quad */
>  
> -	ip_addr[quads] = strtoul(addr, &tmp, 0);
> +	ip_addr[quads] = strtol(addr, &tmp, 0);
>  
>  	if (tmp == addr)	/* expected a digit, found something else */
>  	    return 0;
>  
> +	if (ip_addr[quads] < 0 || ip_addr[quads] > 255) {
> +	    /* invalid octet */
> +	    return 0;
> +	}
> +
>  	addr = tmp;
>  
>  	if (*addr == '.' && quads != 3)
> @@ -919,14 +924,14 @@
>  
>  	++addr;
>  
> -	bits = strtoul(addr, &tmp, 0);
> +	bits = strtol(addr, &tmp, 0);
>  
>  	if (tmp == addr)	/* expected a digit, found something else */
>  	    return 0;
>  
>  	addr = tmp;
>  
> -	if (bits > 32)		/* netmask must be between 0 and 32 */
> +	if (bits < 0 || bits > 32)	/* netmask must be between 0 and 32 */
>  	    return 0;
>  
>      }
> 
>