Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix GH-17037: UAF in user filter when adding existing filter name due to incorrect error handling
This commit is contained in:
Niels Dossche 2024-12-04 20:05:38 +01:00
commit f108eecf7c
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
2 changed files with 16 additions and 4 deletions

View file

@ -0,0 +1,8 @@
--TEST--
GH-17037 (UAF in user filter when adding existing filter name due to incorrect error handling)
--FILE--
<?php
var_dump(stream_filter_register('string.toupper', 'filter_string_toupper'));
?>
--EXPECT--
bool(false)

View file

@ -521,13 +521,17 @@ PHP_FUNCTION(stream_filter_register)
fdat = ecalloc(1, sizeof(struct php_user_filter_data)); fdat = ecalloc(1, sizeof(struct php_user_filter_data));
fdat->classname = zend_string_copy(classname); fdat->classname = zend_string_copy(classname);
if (zend_hash_add_ptr(BG(user_filter_map), filtername, fdat) != NULL && if (zend_hash_add_ptr(BG(user_filter_map), filtername, fdat) != NULL) {
php_stream_filter_register_factory_volatile(filtername, &user_filter_factory) == SUCCESS) { if (php_stream_filter_register_factory_volatile(filtername, &user_filter_factory) == SUCCESS) {
RETVAL_TRUE; RETURN_TRUE;
}
zend_hash_del(BG(user_filter_map), filtername);
} else { } else {
zend_string_release_ex(classname, 0); zend_string_release_ex(classname, 0);
efree(fdat); efree(fdat);
RETVAL_FALSE;
} }
RETURN_FALSE;
} }
/* }}} */ /* }}} */