Skip to content

Commit

Permalink
Fix #179: uopz_set_static() does not check that $static is an array
Browse files Browse the repository at this point in the history
Instead of using the very generic `z` type specifier, we use the `a`
specifier of ZPP to avoid accepting anything but an array.  We also add
an assertion to make it clear to readers that `statics` is actually an
array at this point.
  • Loading branch information
cmb69 committed Aug 3, 2024
1 parent 0a87ecb commit d7a4ae8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ zend_bool uopz_set_static(zend_class_entry *clazz, zend_string *function, zval *
zval_ptr_dtor(v);
}

ZEND_ASSERT(Z_TYPE_P(statics) == IS_ARRAY);
if (!(y = zend_hash_find(Z_ARRVAL_P(statics), k))) {
ZVAL_NULL(v);

Expand Down
17 changes: 17 additions & 0 deletions tests/bugs/gh179.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
uopz_set_static() does not check that $static is an array
--EXTENSIONS--
uopz
--INI--
uopz.disable=0
--FILE--
<?php
function foo() {
static $a = "a";
}

uopz_set_static("foo", 42);
?>
--EXPECTF--
Fatal error: Uncaught InvalidArgumentException: unexpected parameter combination, expected (class, function, statics) or (function, statics) in %s:%d
%A
4 changes: 2 additions & 2 deletions uopz.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ static PHP_FUNCTION(uopz_set_static)

uopz_disabled_guard();

if (uopz_parse_parameters("CSz", &clazz, &function, &statics) != SUCCESS &&
uopz_parse_parameters("Sz", &function, &statics) != SUCCESS) {
if (uopz_parse_parameters("CSa", &clazz, &function, &statics) != SUCCESS &&
uopz_parse_parameters("Sa", &function, &statics) != SUCCESS) {
uopz_refuse_parameters(
"unexpected parameter combination, expected (class, function, statics) or (function, statics)");
return;
Expand Down

0 comments on commit d7a4ae8

Please sign in to comment.