Skip to content
Merged
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
7 changes: 7 additions & 0 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -4327,8 +4327,15 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data *ca
} \
} while (0)

#if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL
# define ZEND_VM_KIND_TAILCALL_SAVE_OPLINE() SAVE_OPLINE()
#else
# define ZEND_VM_KIND_TAILCALL_SAVE_OPLINE()
#endif

#define ZEND_VM_LOOP_INTERRUPT_CHECK() do { \
if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
ZEND_VM_KIND_TAILCALL_SAVE_OPLINE(); \
ZEND_VM_LOOP_INTERRUPT(); \
} \
} while (0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Test Uri\WhatWg\Url component modification - error - modifying multiple components with warnings before throwing an exception
--FILE--
<?php

$url = new Uri\WhatWg\Url("https://example.com")
->withScheme("\tscheme")
->withHost("\tex.com")
->withQuery("\refoo=bar")
->withFragment("\nfoo");

try {
$url->withScheme("0");
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
var_dump($e->errors);
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified scheme is malformed
array(0) {
}
16 changes: 16 additions & 0 deletions ext/uri/uri_parser_whatwg.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ static zend_result php_uri_parser_whatwg_scheme_write(void *uri, zval *value, zv

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_protocol_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "scheme");

Expand Down Expand Up @@ -304,6 +306,8 @@ static zend_result php_uri_parser_whatwg_username_write(void *uri, zval *value,

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_username_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "username");

Expand Down Expand Up @@ -333,6 +337,8 @@ static zend_result php_uri_parser_whatwg_password_write(void *uri, zval *value,

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_password_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "password");

Expand Down Expand Up @@ -418,6 +424,8 @@ static zend_result php_uri_parser_whatwg_host_write(void *uri, zval *value, zval

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_hostname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "host");

Expand Down Expand Up @@ -447,6 +455,8 @@ static zend_result php_uri_parser_whatwg_port_write(void *uri, zval *value, zval

zval_long_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_port_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "port");

Expand Down Expand Up @@ -476,6 +486,8 @@ static zend_result php_uri_parser_whatwg_path_write(void *uri, zval *value, zval

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_pathname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "path");

Expand Down Expand Up @@ -505,6 +517,8 @@ static zend_result php_uri_parser_whatwg_query_write(void *uri, zval *value, zva

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_search_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "query string");

Expand Down Expand Up @@ -534,6 +548,8 @@ static zend_result php_uri_parser_whatwg_fragment_write(void *uri, zval *value,

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_hash_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "fragment");

Expand Down
29 changes: 29 additions & 0 deletions ext/zend_test/tests/observer_vm_interrupt_tailcall_return.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Observer: VM interrupt during tailcall return to caller
--DESCRIPTION--
This exercises a VM interrupt raised immediately before a user function returns
to a caller that invoked it through DO_FCALL. On the tailcall VM, the caller's
saved opline must point to the opcode after DO_FCALL before a pending interrupt
is handled.
--EXTENSIONS--
zend_test
--INI--
opcache.jit=0
zend_test.observer.set_vm_interrupt_on_begin=1
--FILE--
<?php
function interrupt_before_return(VmInterruptComparable $left, VmInterruptComparable $right): void
{
$left < $right;
}

function call_interrupt_before_return(): void
{
interrupt_before_return(new VmInterruptComparable(2), new VmInterruptComparable(1));
}

call_interrupt_before_return();
echo "ok\n";
?>
--EXPECT--
ok
Loading