Skip to content
Closed
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ PHP NEWS
. Fix persistent free of non-persistent connect_attr key (David Carlier).

- Opcache:
. Fixed bug GH-21972 (Corrupted variable type when a typed by-value return
contains a reference wrapper). (Weilin Du)
. Fixed tracing JIT crash when a VM interrupt is handled during an observed
user function call. (Levi Morrison)
. Fixed bug GH-22004 (Assertion failure at ext/opcache/jit/zend_jit_trace.c).
Expand Down
5 changes: 4 additions & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -4387,7 +4387,7 @@ ZEND_VM_COLD_CONST_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV
ZVAL_DEREF(retval_ptr);
}

if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ptr)))) {
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ref)))) {
ZEND_VM_NEXT_OPCODE();
}

Expand Down Expand Up @@ -4417,6 +4417,9 @@ ZEND_VM_COLD_CONST_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV
}
retval_ptr = retval_ref;
}
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ptr)))) {
ZEND_VM_NEXT_OPCODE();
}
}

SAVE_OPLINE();
Expand Down
25 changes: 20 additions & 5 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
zval *sortkey, *tmp;

num_keys = zend_hash_num_elements(Z_ARRVAL_P(val));
sort_keys = safe_emalloc((num_keys+1), sizeof(LDAPSortKey*), 0);
sort_keys = ecalloc((num_keys+1), sizeof(LDAPSortKey*));
tmpstrings1 = safe_emalloc(num_keys, sizeof(zend_string*), 0);
tmpstrings2 = safe_emalloc(num_keys, sizeof(zend_string*), 0);
num_tmpstrings1 = 0;
Expand Down
30 changes: 30 additions & 0 deletions ext/ldap/tests/ldap_sort_control_missing_attr.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
ldap_search(): malformed sort control (sort key missing "attr") must not free uninitialized memory
--EXTENSIONS--
ldap
--FILE--
<?php
// No server needed: the control array is validated before the search is sent.
// A sort key missing "attr" makes php_ldap_control_from_array() bail mid-loop;
// the failure cleanup must not walk/free the partially built sort_keys array.
$ld = ldap_connect("ldap://127.0.0.1:389");

try {
ldap_search($ld, "dc=example,dc=com", "(objectClass=*)", [], 0, -1, -1, LDAP_DEREF_NEVER, [
[
'oid' => LDAP_CONTROL_SORTREQUEST,
'value' => [
['attr' => 'cn'],
['reverse' => true],
],
],
]);
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}

echo "ok\n";
?>
--EXPECT--
ldap_search(): Sort key list must have an "attr" key
ok
39 changes: 39 additions & 0 deletions ext/opcache/tests/opt/gh21972.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
GH-21972: Typed by-value return must not leak reference wrapper
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
--EXTENSIONS--
opcache
--FILE--
<?php
declare(strict_types=1);

enum ValueType {
case BOOL;
case MIXED;
}

function applyDefinition(
bool &$lazy = false,
ValueType &$type = ValueType::MIXED,
int &$flags = 0,
?string &$default = null,
): void {
}

function getTypedValue(string $default, bool $lazy, ValueType $type): string {
applyDefinition($lazy, $type, default: $default);
return $default;
}

$value = getTypedValue('false', false, ValueType::BOOL);
var_dump(gettype($value));
var_dump(strtolower($value));
var_dump(strtolower(getTypedValue('FALSE', false, ValueType::BOOL)));
?>
--EXPECT--
string(6) "string"
string(5) "false"
string(5) "false"
Loading