Skip to content

Commit 81fd4e8

Browse files
authored
Replace zend_atol with zend_ini_prse_quantity (#5477)
1 parent 51ead69 commit 81fd4e8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ext-src/php_swoole.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,18 @@ SW_API bool php_swoole_is_enable_coroutine() {
349349

350350
SW_API zend_long php_swoole_parse_to_size(zval *zv) {
351351
if (ZVAL_IS_STRING(zv)) {
352+
#if PHP_VERSION_ID >= 80200
353+
zend_string *errstr;
354+
auto size = zend_ini_parse_quantity(Z_STR_P(zv), &errstr);
355+
if (errstr) {
356+
php_swoole_fatal_error(
357+
E_ERROR, "failed to parse '%s' to size, Error: %s", Z_STRVAL_P(zv), ZSTR_VAL(errstr));
358+
zend_string_release(errstr);
359+
}
360+
return size;
361+
#else
352362
return zend_atol(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
363+
#endif
353364
} else {
354365
return zval_get_long(zv);
355366
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
swoole_server: parse option value to size
3+
--SKIPIF--
4+
<?php require __DIR__ . '/../include/skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
require __DIR__ . '/../include/bootstrap.php';
8+
9+
use Swoole\Server;
10+
11+
$server = new Server('127.0.0.1', 0);
12+
$server->set([
13+
'buffer_output_size' => '2M',
14+
]);
15+
$server->set([
16+
'buffer_output_size' => 2 * 1024 * 1024,
17+
]);
18+
$server->set([
19+
'buffer_output_size' => 'xxx--2M',
20+
]);
21+
?>
22+
--EXPECTF--
23+
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
24+

0 commit comments

Comments
 (0)