Skip to content

Fix memory leak in shm_get_var() when variable is corrupted#21388

Open
ndossche wants to merge 2 commits intophp:PHP-8.4from
ndossche:fix-shm-laek
Open

Fix memory leak in shm_get_var() when variable is corrupted#21388
ndossche wants to merge 2 commits intophp:PHP-8.4from
ndossche:fix-shm-laek

Conversation

@ndossche
Copy link
Member

@ndossche ndossche commented Mar 8, 2026

This path wasn't tested (clearly).
To trigger this we use FFI, which seemed like the easiest way that doesn't involve using another process messing with the shared memory.

There are more mistakes against php_var_unserialize to be found, but it just takes a while to come up with a test that triggers the necessary code paths.

This path wasn't tested (clearly).
To trigger this we use FFI, which seemed like the easiest way that
doesn't involve using another process messing with the shared memory.
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (php_var_unserialize(return_value, (const unsigned char **) &shm_data, (unsigned char *) shm_data + shm_var->length, &var_hash) != 1) {
int res = php_var_unserialize(return_value, (const unsigned char **) &shm_data, (unsigned char *) shm_data + shm_var->length, &var_hash);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
Copy link
Member

@devnexen devnexen Mar 9, 2026

Choose a reason for hiding this comment

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

is it possible to minimise the change (i.e. keeping RETVAL_FALSE) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Someone else is going to change it to RETURN_FALSE on master anyway, so might as well already do it

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