Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace zend_atol with zend_ini_prse_quantity #5477

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,18 @@ SW_API bool php_swoole_is_enable_coroutine() {

SW_API zend_long php_swoole_parse_to_size(zval *zv) {
if (ZVAL_IS_STRING(zv)) {
#if PHP_VERSION_ID >= 80200
zend_string *errstr;
auto size = zend_ini_parse_quantity(Z_STR_P(zv), &errstr);
if (errstr) {
php_swoole_fatal_error(
E_ERROR, "failed to parse '%s' to size, Error: %s", Z_STRVAL_P(zv), ZSTR_VAL(errstr));
zend_string_release(errstr);
}
return size;
#else
return zend_atol(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
#endif
} else {
return zval_get_long(zv);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/swoole_server/parse_option_to_size.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
swoole_server: parse option value to size
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Server;

$server = new Server('127.0.0.1', 0);
$server->set([
'buffer_output_size' => '2M',
]);
$server->set([
'buffer_output_size' => 2 * 1024 * 1024,
]);
$server->set([
'buffer_output_size' => 'xxx--2M',
]);
?>
--EXPECTF--
Fatal error: Swoole\Server::set(): failed to parse 'xxx--2M' to size, Error: Invalid quantity "xxx--2M": no valid leading digits, interpreting as "0" for backwards compatibility in %s on line %d

Loading