Skip to content

Fix GH-25487: sodium_memzero() sets a typed property to null without TypeError - #25488

Open
lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25487
Open

lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25487

Conversation

@lazerg

@lazerg lazerg commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

sodium_memzero() cleared its argument with convert_to_null() on the dereferenced value, so the type of a typed property holding the reference was never checked and a string property ended up as null. Now, when a property type does not allow null, the property keeps a string of NUL bytes with the same length instead. Nullable and untyped targets still become null. sodium_crypto_generichash_final() had the same problem with its $state argument and gets the same fix.

Fixes #25487

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is the correct fix: Leaving the original string unmodified for sodium_memzero() violates user expectations. For a typed property the string should probably be replaced by an all-NUL string of the same length or something like that.

@lazerg

lazerg commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Changed in 2c74e39: if the property type doesn't allow null, it now keeps a NUL-filled string of the same length, and nullable properties still get null. sodium_crypto_generichash_final() works the same way.

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.

2 participants