From:             ckruse at wwwtech dot de
Operating system: All
PHP version:      4.3.3
PHP Bug Type:     Network related
Bug description:  ip2long() uses the obsolete inet_addr() interface

Description:
------------
PHP uses in the ip2long() function the obsolete inet_addr() interface
which makes it impossible to detect errors in the input values:
inet_addr() converts 255.255.255.255 to -1, which is correct. But in error
case it also returns INADDR_NONE, wich is usually defined as -1. Therefore
the inet_aton() function should be used. I made a little patch which
corrects this.

Actual result:
--------------
1223a1224
>   struct in_addr in;
1231c1232,1237
<       RETURN_LONG(ntohl(inet_addr(Z_STRVAL_PP(str))));
---
>   if(inet_aton(Z_STRVAL_PP(str),&inp) == 0) {
>     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid address");
>     RETURN_NULL();
>   }
> 
>   RETURN_LONG(ntohl(inp.s_addr));


-- 
Edit bug report at http://bugs.php.net/?id=25487&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25487&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25487&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25487&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25487&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25487&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25487&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25487&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25487&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25487&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25487&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25487&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25487&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25487&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25487&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25487&r=gnused

Reply via email to