diff --git a/Zend/tests/zend_atol.phpt b/Zend/tests/zend_atol.phpt new file mode 100644 index 0000000000000..74562af74b18a --- /dev/null +++ b/Zend/tests/zend_atol.phpt @@ -0,0 +1,360 @@ +--TEST-- +Test parsing of INI "size" values (e.g. "16M") +--EXTENSIONS-- +zend_test +--FILE-- +0) { switch (str[str_len-1]) { case 'g': @@ -162,8 +183,20 @@ ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* { case 'K': retval *= 1024; break; + default: + /* Unknown suffix */ + zend_error(E_WARNING, "Invalid numeric string '%.*s', interpreting as '%.*s' for backwards compatibility", + (int)str_len, str, (int)(digits_end - str), str); + return retval; } } + + if (digits_end < &str[str_len-1]) { + /* More than one character in suffix */ + zend_error(E_WARNING, "Invalid numeric string '%.*s', interpreting as '%.*s%c' for backwards compatibility", + (int)str_len, str, (int)(digits_end - str), str, str[str_len-1]); + } + return (zend_long) retval; } /* }}} */ @@ -3322,7 +3355,7 @@ ZEND_API zend_uchar ZEND_FASTCALL _is_numeric_string_ex(const char *str, size_t /* Skip any whitespace * This is much faster than the isspace() function */ - while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' || *str == '\v' || *str == '\f') { + while (ZEND_IS_WHITESPACE(*str)) { str++; length--; } diff --git a/ext/ffi/tests/bug78270_1.phpt b/ext/ffi/tests/bug78270_1.phpt index edc212bdd2cf5..4e45bf93b9597 100644 --- a/ext/ffi/tests/bug78270_1.phpt +++ b/ext/ffi/tests/bug78270_1.phpt @@ -27,7 +27,7 @@ require_once('utils.inc'); $ffi = FFI::cdef(<<bug78270("17.4", 4)); +var_dump($ffi->bug78270("17", 2)); ?> --EXPECT-- int(17) diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index f785303c936a7..44d20e5e19d00 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -165,7 +165,7 @@ static ZEND_INI_MH(OnUpdateJit) static ZEND_INI_MH(OnUpdateJitDebug) { zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); - zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); + zend_long val = ZEND_ATOL(ZSTR_VAL(new_value)); if (zend_jit_debug_config(*p, val, stage) == SUCCESS) { *p = val; diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 09f67b2e3f60b..b201cee435349 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2505,7 +2505,7 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int cal } if (!(Z_STRLEN_P(arg1) > 1 && Z_STRVAL_P(arg1)[0] == '0') && is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) == IS_LONG) { - zend_ulong key = (zend_ulong) zend_atol(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)); + zend_ulong key = (zend_ulong) ZEND_STRTOUL(Z_STRVAL_P(arg1), NULL, 0); if ((find_hash = zend_hash_index_find(Z_ARRVAL_P(arr), key)) == NULL) { array_init(&hash); find_hash = zend_hash_index_add_new(Z_ARRVAL_P(arr), key, &hash); diff --git a/ext/standard/tests/general_functions/parse_ini_numeric_entry_name.phpt b/ext/standard/tests/general_functions/parse_ini_numeric_entry_name.phpt new file mode 100644 index 0000000000000..a359a9f38285b --- /dev/null +++ b/ext/standard/tests/general_functions/parse_ini_numeric_entry_name.phpt @@ -0,0 +1,23 @@ +--TEST-- +parse_ini_string with numeric entry name +--FILE-- + + array(1) { + [0]=> + string(1) "1" + } + ["2M"]=> + array(1) { + [0]=> + string(1) "2" + } +} diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index b8ad6c5b46c03..b3490ca81c8d7 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -307,6 +307,17 @@ static ZEND_FUNCTION(zend_get_unit_enum) RETURN_OBJ_COPY(zend_enum_get_case_cstr(zend_test_unit_enum, "Foo")); } +static ZEND_FUNCTION(zend_test_zend_atol) +{ + zend_string *str; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(str) + ZEND_PARSE_PARAMETERS_END(); + + RETURN_LONG(zend_atol(ZSTR_VAL(str), ZSTR_LEN(str))); +} + static ZEND_FUNCTION(namespaced_func) { ZEND_PARSE_PARAMETERS_NONE(); diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php index b8dff45c340de..988dd09ba466a 100644 --- a/ext/zend_test/test.stub.php +++ b/ext/zend_test/test.stub.php @@ -92,6 +92,8 @@ function zend_weakmap_remove(object $object): bool {} function zend_weakmap_dump(): array {} function zend_get_unit_enum(): ZendTestUnitEnum {} + + function zend_test_zend_atol(string $str): int {} } namespace ZendTestNS { diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h index 19cf8ffbd2539..af11f59665e2b 100644 --- a/ext/zend_test/test_arginfo.h +++ b/ext/zend_test/test_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7326163f8ce5340c12e74af72d47a8926eb39786 */ + * Stub hash: 6ab822237eacd3831c1d8dea23b7d5e4c88e4a88 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -71,6 +71,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_zend_get_unit_enum, 0, 0, ZendTestUnitEnum, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_zend_atol, 0, 1, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ZendTestNS2_ZendSubNS_namespaced_func, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -116,6 +120,7 @@ static ZEND_FUNCTION(zend_weakmap_attach); static ZEND_FUNCTION(zend_weakmap_remove); static ZEND_FUNCTION(zend_weakmap_dump); static ZEND_FUNCTION(zend_get_unit_enum); +static ZEND_FUNCTION(zend_test_zend_atol); static ZEND_FUNCTION(namespaced_func); static ZEND_METHOD(_ZendTestClass, is_object); static ZEND_METHOD(_ZendTestClass, __toString); @@ -147,6 +152,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(zend_weakmap_remove, arginfo_zend_weakmap_remove) ZEND_FE(zend_weakmap_dump, arginfo_zend_weakmap_dump) ZEND_FE(zend_get_unit_enum, arginfo_zend_get_unit_enum) + ZEND_FE(zend_test_zend_atol, arginfo_zend_test_zend_atol) ZEND_NS_FE("ZendTestNS2\\ZendSubNS", namespaced_func, arginfo_ZendTestNS2_ZendSubNS_namespaced_func) ZEND_FE_END };