From c9a9dee2980e2e44e2727c1019668d92cd425f9c Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Fri, 19 Dec 2003 13:33:51 +0000 Subject: [PATCH] Fixed bug #26667 (Added safety checks to ip2long()). --- ext/standard/basic_functions.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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)); } /* }}} */ -- 2.50.1