Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #172: handle ZEND_VERIFY_NEVER_TYPE when uopz.exit is disabled #173

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 30 additions & 3 deletions src/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@

ZEND_EXTERN_MODULE_GLOBALS(uopz);

#if PHP_VERSION_ID >= 80100
#define UOPZ_HANDLERS_COUNT 13
#else
#define UOPZ_HANDLERS_COUNT 12
#endif

#ifdef ZEND_VM_FP_GLOBAL_REG
# define UOPZ_OPCODE_HANDLER_ARGS
Expand Down Expand Up @@ -99,6 +103,9 @@ typedef struct _uopz_vm_handler_t {
} uopz_vm_handler_t;

zend_vm_handler_t zend_vm_exit;
#if PHP_VERSION_ID >= 80100
zend_vm_handler_t zend_vm_verify_never_type;
#endif
zend_vm_handler_t zend_vm_new;
zend_vm_handler_t zend_vm_fetch_constant;
zend_vm_handler_t zend_vm_do_fcall;
Expand All @@ -112,6 +119,9 @@ zend_vm_handler_t zend_vm_init_method_call;
zend_vm_handler_t zend_vm_init_static_method_call;

int uopz_vm_exit(UOPZ_OPCODE_HANDLER_ARGS);
#if PHP_VERSION_ID >= 80100
int uopz_vm_verify_never_type(UOPZ_OPCODE_HANDLER_ARGS);
#endif
int uopz_vm_new(UOPZ_OPCODE_HANDLER_ARGS);
int uopz_vm_fetch_constant(UOPZ_OPCODE_HANDLER_ARGS);
int uopz_vm_do_fcall(UOPZ_OPCODE_HANDLER_ARGS);
Expand All @@ -125,6 +135,9 @@ int uopz_vm_init_static_method_call(UOPZ_OPCODE_HANDLER_ARGS);

UOPZ_HANDLERS_DECL_BEGIN()
UOPZ_HANDLER_DECL(ZEND_EXIT, exit)
#if PHP_VERSION_ID >= 80100
UOPZ_HANDLER_DECL(ZEND_VERIFY_NEVER_TYPE, verify_never_type)
#endif
UOPZ_HANDLER_DECL(ZEND_NEW, new)
UOPZ_HANDLER_DECL(ZEND_FETCH_CONSTANT, fetch_constant)
UOPZ_HANDLER_DECL(ZEND_FETCH_CLASS_CONSTANT, fetch_class_constant)
Expand Down Expand Up @@ -155,7 +168,7 @@ void uopz_handlers_init(void) {

void uopz_handlers_shutdown(void) {
uopz_vm_handler_t *handler = uopz_vm_handlers;

while (handler) {
if (!handler->opcode) {
break;
Expand All @@ -173,6 +186,12 @@ static zend_always_inline int _uopz_vm_dispatch(UOPZ_OPCODE_HANDLER_ARGS) {
zend = zend_vm_exit;
break;

#if PHP_VERSION_ID >= 80100
case ZEND_VERIFY_NEVER_TYPE:
zend = zend_vm_verify_never_type;
break;
#endif

case ZEND_NEW:
zend = zend_vm_new;
break;
Expand All @@ -195,7 +214,7 @@ static zend_always_inline int _uopz_vm_dispatch(UOPZ_OPCODE_HANDLER_ARGS) {

case ZEND_INIT_STATIC_METHOD_CALL:
zend = zend_vm_init_static_method_call;
break;
break;

case ZEND_FETCH_CONSTANT:
zend = zend_vm_fetch_constant;
Expand Down Expand Up @@ -267,14 +286,22 @@ int uopz_vm_exit(UOPZ_OPCODE_HANDLER_ARGS) { /* {{{ */
}
} /* }}} */

#if PHP_VERSION_ID >= 80100
int uopz_vm_verify_never_type(UOPZ_OPCODE_HANDLER_ARGS) { /* {{{ */
if (UOPZ(exit)) {
UOPZ_VM_DISPATCH();
} else UOPZ_VM_RETURN();
} /* }}} */
#endif

int uopz_vm_new(UOPZ_OPCODE_HANDLER_ARGS) { /* {{{ */
UOPZ_USE_OPLINE;
zval *result;
zend_function *constructor;
zend_class_entry *ce;
zend_execute_data *call;
zend_object *obj = NULL;

UOPZ_SAVE_OPLINE();

if (opline->op1_type == IS_CONST) {
Expand Down
36 changes: 36 additions & 0 deletions tests/bugs/gh172.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
handle ZEND_VERIFY_NEVER_TYPE when uopz.exit disabled
--EXTENSIONS--
uopz
--SKIPIF--
<?php
uopz_allow_exit(true);
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
die("skip PHP 8.1+ only");
}
--INI--
uopz.disable=0
uopz.exit=0
opcache.enable_cli=0
xdebug.enable=0
--FILE--
<?php

uopz_allow_exit(false);
function x(): never {
exit(10);
}

x();

var_dump(uopz_get_exit_status());

uopz_allow_exit(true);

exit(20);

echo "not here\n";

?>
--EXPECT--
int(10)
26 changes: 26 additions & 0 deletions tests/bugs/gh172a.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
do not handle ZEND_VERIFY_NEVER_TYPE if not uopz_allow_exit
--EXTENSIONS--
uopz
--SKIPIF--
<?php
uopz_allow_exit(true);
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
die("skip PHP 8.1+ only");
}
--INI--
uopz.disable=0
uopz.exit=1
opcache.enable_cli=0
xdebug.enable=0
--FILE--
<?php

function x(): never {
return "here";
}
x();

?>
--EXPECTF--
Fatal error: A never-returning function must not return in %s