Skip to content

Commit 685e6e4

Browse files
committed
Fixes
1 parent 5c30acd commit 685e6e4

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

Zend/zend_compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4562,6 +4562,10 @@ static zend_result zend_compile_frameless_icall(znode *result, zend_ast_list *ar
45624562
return FAILURE;
45634563
}
45644564

4565+
if (args->children > 3) {
4566+
return FAILURE;
4567+
}
4568+
45654569
/* We don't support named arguments or argument unpacking. */
45664570
for (uint32_t i = 0; i < args->children; i++) {
45674571
zend_ast *arg = args->child[i];
@@ -4588,6 +4592,7 @@ static zend_result zend_compile_frameless_icall(znode *result, zend_ast_list *ar
45884592
}
45894593
uint8_t opcode = ZEND_FRAMELESS_ICALL_0 + args->children;
45904594
zend_op *opline = zend_emit_op_tmp(result, opcode, NULL, NULL);
4595+
opline->extended_value = offset;
45914596
if (args->children >= 1) {
45924597
SET_NODE(opline->op1, &arg1);
45934598
}
@@ -4597,7 +4602,6 @@ static zend_result zend_compile_frameless_icall(znode *result, zend_ast_list *ar
45974602
if (args->children >= 3) {
45984603
zend_emit_op_data(&arg3);
45994604
}
4600-
opline->extended_value = offset;
46014605
return SUCCESS;
46024606
}
46034607
frameless_function_info++;

Zend/zend_frameless_function.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
zend_wrong_parameter_type_error(arg_num, Z_EXPECTED_LONG, arg ## arg_num); \
5050
goto flf_clean; \
5151
}
52+
#define Z_FLF_PARAM_LONG_OR_NULL(arg_num, is_null, dest) \
53+
if (!zend_parse_arg_long(arg ## arg_num, &dest, &is_null, /* null_check */ true, arg_num)) { \
54+
zend_wrong_parameter_type_error(arg_num, Z_EXPECTED_LONG_OR_NULL, arg ## arg_num); \
55+
goto flf_clean; \
56+
}
5257
#define Z_FLF_PARAM_STR(arg_num, dest, tmp) \
5358
if (Z_TYPE_P(arg ## arg_num) == IS_STRING) { \
5459
dest = Z_STR_P(arg ## arg_num); \

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ function chunk_split(string $string, int $length = 76, string $separator = "\r\n
24252425
/**
24262426
* @compile-time-eval
24272427
* @frameless-function {"arity": 2}
2428+
* @frameless-function {"arity": 3}
24282429
*/
24292430
function substr(string $string, int $offset, ?int $length = null): string {}
24302431

ext/standard/basic_functions_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/string.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,12 +2206,13 @@ ZEND_FRAMELESS_FUNCTION(substr, 3)
22062206
zval str_tmp;
22072207
zend_string *str;
22082208
zend_long f, l;
2209+
bool len_is_null;
22092210

22102211
Z_FLF_PARAM_STR(1, str, str_tmp);
22112212
Z_FLF_PARAM_LONG(2, f);
2212-
Z_FLF_PARAM_LONG(3, l);
2213+
Z_FLF_PARAM_LONG_OR_NULL(3, len_is_null, l);
22132214

2214-
_zend_substr(return_value, str, f, /* len_is_null */ false, l);
2215+
_zend_substr(return_value, str, f, len_is_null, l);
22152216

22162217
flf_clean:
22172218
Z_FLF_PARAM_FREE_STR(1, str_tmp);

0 commit comments

Comments
 (0)