#25487 [Opn->Asn]: ip2long() uses the obsolete inet_addr() interface

From: Date: Thu, 11 Sep 2003 13:15:20 +0000
Subject: #25487 [Opn->Asn]: ip2long() uses the obsolete inet_addr() interface
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-47445@lists.php.net to get a copy of this message
ID: 25487 Updated by: iliaa@php.net Reported By: ckruse at wwwtech dot de -Status: Open +Status: Assigned Bug Type: Network related Operating System: All PHP Version: 4.3.3 -Assigned To: +Assigned To: iliaa Previous Comments: ------------------------------------------------------------------------ [2003-09-11 06:31:10] ckruse at wwwtech dot de 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 this bug report at http://bugs.php.net/?id=25487&edit=1

« previous php.bugs (#47445) next »