From: Ilia Alshanetsky Date: Fri, 19 Dec 2003 13:33:51 +0000 (+0000) Subject: Fixed bug #26667 (Added safety checks to ip2long()). X-Git-Tag: php-5.0.0b3RC2~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9a9dee2980e2e44e2727c1019668d92cd425f9c;p=php Fixed bug #26667 (Added safety checks to ip2long()). --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 3912e37db2..7e5e89c328 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1181,6 +1181,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; @@ -1188,7 +1189,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)); } /* }}} */