[php-src] Issue #16138: PHP Crashs When Execution For Function Calls Opcodes
| From: | tahaghafuri | Date: | Mon, 30 Sep 2024 19:27:23 +0000 |
| Subject: | [php-src] Issue #16138: PHP Crashs When Execution For Function Calls Opcodes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247953@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/16138
Author: tahaghafuri
### Description
The following code:
```php
<?php
file_put_contents("output.txt", "This is some content to write to a file.");
```
Resulted in this output:
The PHP Crashs,
```
static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL
ZEND_INIT_FCALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
zval *fname;
zval *func;
zend_function *fbc;
zend_execute_data *call;
fbc = CACHED_PTR(opline->result.num);
if (UNEXPECTED(fbc == NULL)) {
fname = (zval*)RT_CONSTANT(opline, opline->op2);
func = zend_hash_find_known_hash(EG(function_table), Z_STR_P(fname));
ZEND_ASSERT(func != NULL && "Function existence must be checked at compile
time");
fbc = Z_FUNC_P(func); <<<<-- IS NULL
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) &&
UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
init_func_run_time_cache(&fbc->op_array);
}
CACHE_PTR(opline->result.num, fbc);
}
call = _zend_vm_stack_push_call_frame_ex(
opline->op1.num, ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, NULL);
call->prev_execute_data = EX(call);
EX(call) = call;
ZEND_VM_NEXT_OPCODE();
}

Crash Point:

```
But I expected this output instead:
```
Write Sample Content To File.
```
Also I Think The PHP Needs Check Function Existence At Execution Time, If Not Exist Show Error.
### PHP Version
PHP 8.3.12
### Operating System
Windows 11