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 @@ -34,6 +34,8 @@ PHP NEWS
. Fixed bug GH-22265 (Another tailcall vm_interrupt bug). (Levi Morrison)
. Fixed bug GH-20469 (Unsafe inheritance cache replay with reentrant
autoloading). (Levi Morrison)
. Fixed bug GH-21972 (Corrupted variable type when a typed by-value return
contains a reference wrapper). (Weilin Du)

- Phar:
. Fixed a bypass of the magic ".phar" directory protection in
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 @@ -4454,7 +4454,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 @@ -4483,6 +4483,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.

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"
10 changes: 5 additions & 5 deletions ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,12 +1162,12 @@ int make_http_soap_request(
zend_string_release_ex(http_headers, 0);
zend_string_release_ex(http_body, 0);
if (new_uri->scheme == NULL && new_uri->path != NULL) {
new_uri->scheme = new_uri->scheme ? zend_string_copy(new_uri->scheme) : NULL;
new_uri->host = new_uri->host ? zend_string_copy(new_uri->host) : NULL;
new_uri->port = new_uri->port;
new_uri->scheme = uri->scheme ? zend_string_copy(uri->scheme) : NULL;
new_uri->host = uri->host ? zend_string_copy(uri->host) : NULL;
new_uri->port = uri->port;
if (new_uri->path && ZSTR_VAL(new_uri->path)[0] != '/') {
if (new_uri->path) {
char *t = ZSTR_VAL(new_uri->path);
if (uri->path) {
char *t = ZSTR_VAL(uri->path);
char *p = strrchr(t, '/');
if (p) {
zend_string *s = zend_string_alloc((p - t) + ZSTR_LEN(new_uri->path) + 2, 0);
Expand Down
49 changes: 49 additions & 0 deletions ext/soap/tests/bugs/relative_redirect.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
SOAP client follows a redirect with a scheme-less (relative) Location
--EXTENSIONS--
soap
--SKIPIF--
<?php
if (!file_exists(__DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc")) {
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
}
?>
--FILE--
<?php
include __DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc";

$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX];
if (php_ini_loaded_file()) {
$args[] = "-c";
$args[] = php_ini_loaded_file();
}

$code = <<<'PHP'
if ($_SERVER["REQUEST_URI"] === "/redirected") {
header("Content-Type: text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>',
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">',
'<SOAP-ENV:Body><fooResponse><result>ok</result></fooResponse></SOAP-ENV:Body>',
'</SOAP-ENV:Envelope>';
} else {
http_response_code(302);
header("Location: /redirected");
}
PHP;

php_cli_server_start($code, null, $args);

$client = new SoapClient(null, [
'location' => 'http://' . PHP_CLI_SERVER_ADDRESS . '/start',
'uri' => 'test-uri',
]);

try {
$client->__soapCall("foo", []);
echo "redirect followed\n";
} catch (SoapFault $e) {
echo "SoapFault: " . $e->getMessage() . "\n";
}
?>
--EXPECT--
redirect followed
Loading