Skip to content

Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler #12114

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

Closed

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Sep 2, 2023

Reorder when we assign the property value to NULL which is identical to a3a3964

Just for the declared property case instead of dynamic.

zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
/* We set the retval to null AFTER the warning so that an error handler cannot mess
* with the property value... */
ZVAL_NULL(retval);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can leak.

class Foo {}
class C {
    public $a;
    function errorHandler($errno, $errstr) {
        $this->a = new Foo();
    }
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);
(++$c->a);
var_dump($c->a);

Just wrapping the ZVAL_NULL in a if (Z_TYPE_P(retval) == IS_UNDEF) { should do. This will change the behavior to throw a "TypeError: Cannot increment Foo" exception, which I think is what I would expect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we want that, then for consistency the zend_hash_update for the dynamic case should become zend_hash_add instead too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nielsdos That probably makes sense. The leak doesn't happen in that case because the hash table takes care of releasing the old value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK ty, I'll make a PR soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Girgias I think this null should be removed for consistency with a3a3964.

@Girgias Girgias force-pushed the oss-61865-in-dec-declared-prop-undef branch from 962e84f to 28df23b Compare September 3, 2023 13:42
nielsdos added a commit to nielsdos/php-src that referenced this pull request Sep 3, 2023
With the fix in php#12114, the behaviour
would change for non-dynamic properties. Align the behaviour for dynamic
properties to be the same.
nielsdos added a commit that referenced this pull request Sep 3, 2023
With the fix in #12114, the behaviour
would change for non-dynamic properties. Align the behaviour for dynamic
properties to be the same.

Closes GH-12117.
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine

…at is unset in error handler

Reorder when we assign the property value to NULL which is identical to
a3a3964

Just for the declared property case instead of dynamic.
@Girgias Girgias force-pushed the oss-61865-in-dec-declared-prop-undef branch from 28df23b to 9c123ac Compare September 4, 2023 23:24
@Girgias Girgias closed this in 8a392ed Sep 5, 2023
@Girgias Girgias deleted the oss-61865-in-dec-declared-prop-undef branch September 5, 2023 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants