-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Segmentation fault on SoapClient::__getTypes #12392
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
Comments
reproduced even with the master branch. |
|
I can reproduce this as well, weird that the attribute name would be NULL, that's not supposed to happen. |
There are two issues at play here:
Here's what I came up with: use two arrays, the original one and the resulting one after transformation. I'd have to benchmark the performance difference though... diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c
index 68d78326e3..edcc6c4743 100644
--- a/ext/soap/php_schema.c
+++ b/ext/soap/php_schema.c
@@ -2261,17 +2261,21 @@ static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type)
schema_content_model_fixup(ctx, type->model);
}
if (type->attributes) {
- zend_string *str_key;
- zend_ulong index;
+ HashPosition pos;
+ zend_hash_internal_pointer_reset_ex(type->attributes, &pos);
- ZEND_HASH_FOREACH_KEY_PTR(type->attributes, index, str_key, attr) {
- if (str_key) {
+ while ((attr = zend_hash_get_current_data_ptr_ex(type->attributes, &pos)) != NULL) {
+ zend_string *str_key;
+ zend_ulong index;
+
+ if (zend_hash_get_current_key_ex(type->attributes, &str_key, &index, &pos) == HASH_KEY_IS_STRING) {
schema_attribute_fixup(ctx, attr);
+ ZEND_ASSERT(zend_hash_move_forward_ex(type->attributes, &pos) == SUCCESS);
} else {
schema_attributegroup_fixup(ctx, attr, type->attributes);
- zend_hash_index_del(type->attributes, index);
+ ZEND_ASSERT(zend_hash_index_del(type->attributes, index) == SUCCESS);
}
- } ZEND_HASH_FOREACH_END();
+ }
}
}
|
I updated the patch to what should be final, and confirmed that the |
There are two issues: - UAF because the hashmap resized while being iterated over, yet the local variables used internally in the macros are not updated. - The hashmap being iterated over is modified: entries are deleted after other entries have been added. This causes the deletion to fail sometimes because indices of buckets have shifted. Fix it by using a while loop iteration and HashPosition position tracker instead. Issue exists on PHP 8.1 too, but is much harder to trigger. The test file reproduces the issue reliably on PHP 8.2 and up.
There are two issues: - UAF because the hashmap resized while being iterated over, yet the local variables used internally in the macros are not updated. - The hashmap being iterated over is modified: entries are deleted after other entries have been added. This causes the deletion to fail sometimes because indices of buckets have shifted. Fix it by using a while loop iteration and HashPosition position tracker instead. Issue exists on PHP 8.1 too, but is much harder to trigger. The test file reproduces the issue reliably on PHP 8.2 and up.
There are two issues: - UAF because the hashmap resized while being iterated over, yet the local variables used internally in the macros are not updated. - The hashmap being iterated over is modified: entries are deleted after other entries have been added. This causes the deletion to fail sometimes because indices of buckets have shifted. Fix it by using a while loop iteration and HashPosition position tracker instead. Issue exists on PHP 8.1 too, but is much harder to trigger. The test file reproduces the issue reliably on PHP 8.2 and up.
Description
We run into a segmentation fault when calling
SoapClient::__getTypes()
using the WSDL listed below on PHP versions 8.2 and 8.3 (versions 7.4, 8.0 and 8.1 behave as expected, see below).Similar to the following bug (although different PHP versions are affected): https://bugs.php.net/bug.php?id=81154
The following code:
Resulted in this output:
But we expected this output instead:
Tested with different PHP versions via docker:
GDB Backtrace on Debian 12 (bookworm) with PHP 8.2.10 (
./configure --enable-debug --enable-soap
):Any help will be greatly appreciated!
PHP Version
PHP 8.2.11
Operating System
No response
The text was updated successfully, but these errors were encountered: