|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25487 ip2long() uses the obsolete inet_addr() interface
Submitted: 2003-09-11 06:31 UTC Modified: 2003-09-12 00:07 UTC
From: ckruse at wwwtech dot de Assigned: iliaa (profile)
Status: Wont fix Package: Network related
PHP Version: 4.3.3 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
1 + 23 = ?
Subscribe to this entry?

 [2003-09-11 06:31 UTC] ckruse at wwwtech dot de
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 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:
>   struct in_addr in;
<       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));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-12 00:07 UTC]
ip2long() cannot return FALSE because it would break backwards compatibility. This in turn makes changing inet_addr() to inet_aton(), which is not avaliable on all systems pointless.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 23 08:01:24 2023 UTC