Bug #70845 [Com]: ip2long fails with number starting with zero

From: Date: Sat, 19 Dec 2015 01:48:55 +0000
Subject: Bug #70845 [Com]: ip2long fails with number starting with zero
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198016@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70845&edit=1

 ID:                 70845
 Comment by:         ajf@php.net
 Reported by:        raffaellobertini at gmail dot com
 Summary:            ip2long fails with number starting with zero
 Status:             Open
 Type:               Bug
 Package:            Network related
 Operating System:   centos6.5
 PHP Version:        5.4.45
 Block user comment: N
 Private report:     N

 New Comment:

This is merely speculation, but I think it may be interpreting '096' as octal due to the
leading zero. '9' is not a valid octal digit, so in that case, it would be an invalid IP
address.


Previous Comments:
------------------------------------------------------------------------
[2015-11-03 16:28:15] raffaellobertini at gmail dot com

Description:
------------
just run ip2long('195.194.213.096') it will return false instead of 
interpreting the string as '195,194.213.96'

if you point me to the code i fix myself. I mean, the function is not robust.
cannot crash for a number that is '096' that it will be 96 as integer. 



Test script:
---------------
ip2long('195.194.213.096') === ip2long('195,194.213.96')


//anyway the code to convert into packed format is quite easy, but It is not nice that I cannot rely
on php built in function....



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



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


Thread (6 messages)

« previous php.bugs (#198016) next »