#38197 [Bgs->Opn]: ip2long() not accepting hex 0xffffffff

From: Date: Tue, 25 Jul 2006 12:46:06 +0000
Subject: #38197 [Bgs->Opn]: ip2long() not accepting hex 0xffffffff
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-99860@lists.php.net to get a copy of this message
 ID:               38197
 User updated by:  gk at gknw dot de
 Reported By:      gk at gknw dot de
-Status:           Bogus
+Status:           Open
 Bug Type:         Network related
 Operating System: all
 PHP Version:      5.1.4
 New Comment:

I agree that 0xffffffff is not an IP address and the underlying
inet_addr() function doesn't think it's valid - but it doesnt think
it's valid with 255.255.255.255 either, and to capture that there was
code introduced with PHP 5.x.
With only _two_ additional lines of code we could again get the same
behaviour as with PHP 4.x:
=====================================================
--- basic_functions.c.orig	Sun Aug 21 20:36:34 2005
+++ basic_functions.c	Tue Jul 25 11:15:32 2006
@@ -1265,7 +1265,9 @@
 		/* the only special case when we should return -1 ourselves,
 		 * because inet_addr() considers it wrong.
 		 */
-		if (!memcmp(Z_STRVAL_PP(str), "255.255.255.255", Z_STRLEN_PP(str)))
{
+		if (!memcmp(Z_STRVAL_PP(str), "255.255.255.255", Z_STRLEN_PP(str))
||
+				!memcmp(Z_STRVAL_PP(str), "0xffffffff", Z_STRLEN_PP(str)) ||
+				!memcmp(Z_STRVAL_PP(str), "0xFFFFFFFF", Z_STRLEN_PP(str)) ) {
 			RETURN_LONG(-1);
 		}
		
=====================================================
here's a PHP 5.0.5 running with the patch:
http://194.242.35.162/tstphp/t_ip2long.php
and you can see now again same behaviour as with PHP 4.x:
http://www.gknw.de/test/php_issues/t_ip2long.php

patch for download here:
http://www.gknw.net/test/php_issues/basic_functions.c.diff

Guenter.


Previous Comments:
------------------------------------------------------------------------

[2006-07-25 07:04:40] tony2001@php.net

0xffffffff is not an IP address and the underlying inet_addr() function
doesn't think it's valid too.

------------------------------------------------------------------------

[2006-07-24 19:08:23] gk at gknw dot de

Description:
------------
Although ip2long() works fine with 255.255.255.255 it fails when
0xffffffff is passed in.
Other hex values work fine.
Seems this was introduced with PHP 5.x - PHP 4.x is not affected; there
it works as I expect.


Reproduce code:
---------------
Nonworking sample on PHP 5.x:
http://www.gknw.net/test/php_issues/t_ip2long.php
Working same sample on PHP 4.x:
http://www.gknw.de/test/php_issues/t_ip2long.php
Script for download:
http://www.gknw.net/test/php_issues/t_ip2long_php.txt



Expected result:
----------------
Same result on PHP5 as with PHP4.




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=38197&edit=1


Thread (5 messages)

« previous php.bugs (#99860) next »