Skip to content

Commit

Permalink
Fix #167: uopz_set_return() overload confusion
Browse files Browse the repository at this point in the history
If the first ZPP fails, clazz might be assigned, but is not nulled
afterwards.  To avoid potential BC breaks by swapping the ZPPs, we hack
in the nulling of the `clazz`, making use of the short-circuit behavior
of `&&`.
  • Loading branch information
cmb69 committed Aug 3, 2024
1 parent d7a4ae8 commit 5990fa6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/bugs/gh167.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
uopz_set_return() overload confusion
--EXTENSIONS--
uopz
--INI--
uopz.disable=0
--FILE--
<?php
class Foo {}
function foo(): int {
return 42;
}
uopz_set_return("foo", function() {return 4711;}, true);
var_dump(foo());
?>
--EXPECT--
int(4711)
1 change: 1 addition & 0 deletions uopz.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static PHP_FUNCTION(uopz_set_return)
uopz_disabled_guard();

if (uopz_parse_parameters("CSz|b", &clazz, &function, &variable, &execute) != SUCCESS &&
!((clazz = NULL)) &&
uopz_parse_parameters("Sz|b", &function, &variable, &execute) != SUCCESS) {
uopz_refuse_parameters(
"unexpected parameter combination, expected (class, function, variable [, execute]) or (function, variable [, execute])");
Expand Down

0 comments on commit 5990fa6

Please sign in to comment.