]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #26667 (Added safety checks to ip2long()).
authorIlia Alshanetsky <iliaa@php.net>
Fri, 19 Dec 2003 13:33:57 +0000 (13:33 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 19 Dec 2003 13:33:57 +0000 (13:33 +0000)
NEWS
ext/standard/basic_functions.c

diff --git a/NEWS b/NEWS
index 5e3889aee2b22bf80daaf861713fc7ebb063a248..e316d8c3cb10d1fc1b2b55d53ffb600e1a81ed29 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ PHP 4                                                                      NEWS
 - Added a warning when creating temp stream fails with ftp_(n)list(). (Sara)
 - Fixed header handler in NSAPI SAPI module (header->replace was ignored,
   send_default_content_type now sends value from php.ini). (Uwe Schindler)
+- Fixed bug #26667 (Added safety checks to ip2long()). (Ilia)
 - Fixed bug #26639 (mb_convert_variables() clutters variables beyond the
   references). (Moriyoshi)
 - Fixed bug #26635 (fixed look up for fonts in the current directory w/ZTS).
index 94d7ff6192d3e36887c7ff5a094cc823ae61525a..be57962684bb8fc9b16a18893b53e648e5634b0a 100644 (file)
@@ -1229,6 +1229,7 @@ PHP_FUNCTION(constant)
 PHP_FUNCTION(ip2long)
 {
        zval **str;
+       unsigned long int ip;
 
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
                WRONG_PARAM_COUNT;
@@ -1236,7 +1237,11 @@ PHP_FUNCTION(ip2long)
 
        convert_to_string_ex(str);
 
-       RETURN_LONG(ntohl(inet_addr(Z_STRVAL_PP(str))));
+       if (Z_STRVAL_PP(str) == "" || (ip = inet_addr(Z_STRVAL_PP(str))) == INADDR_NONE) {
+               RETURN_LONG(-1);
+       }
+
+       RETURN_LONG(ntohl(ip));
 }
 /* }}} */