From: Ilia Alshanetsky Date: Fri, 19 Dec 2003 13:33:57 +0000 (+0000) Subject: MFH: Fixed bug #26667 (Added safety checks to ip2long()). X-Git-Tag: php-4.3.5RC1~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f3b9cd6917f8a306ff3820a344f78236cdf73b7;p=php MFH: Fixed bug #26667 (Added safety checks to ip2long()). --- diff --git a/NEWS b/NEWS index 5e3889aee2..e316d8c3cb 100644 --- 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). diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 94d7ff6192..be57962684 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -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)); } /* }}} */