Skip to content

Fix validation logic of php:function() callbacks in dom and xsl #12593

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
wants to merge 2 commits into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Nov 2, 2023

Two issues:

  • Assumed that at least 1 argument (function name) was provided.
  • Incorrect error path for the non-callable case.

Two issues:
- Assumed that at least 1 argument (function name) was provided.
- Incorrect error path for the non-callable case.
@nielsdos nielsdos marked this pull request as ready for review November 2, 2023 12:27
Comment on lines 137 to 141
if (obj->stringval == NULL) {
zend_type_error("Handler name must be a string");
xmlXPathFreeObject(obj);
goto cleanup;
goto cleanup_no_callable;
}
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to check that the string is indeed a valid callable before allocating the arguments of it.

Moreover, (for master) you could use the named_params field instead of allocating each argument individually, should make clean-up easier as you would just need to destroy the HashTable.

Copy link
Member Author

Choose a reason for hiding this comment

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

You should be able to check that the string is indeed a valid callable before allocating the arguments of it.

Not easy to do, it's a stack machine so the function name comes last. I'd have to store the past arguments anyway so I can't avoid the allocation.

Moreover, (for master) you could use the named_params field instead of allocating each argument individually, should make clean-up easier as you would just need to destroy the HashTable.

TIL. But that will also be slower because of the hashtable management code.

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to check that the string is indeed a valid callable before allocating the arguments of it.

Not easy to do, it's a stack machine so the function name comes last. I'd have to store the past arguments anyway so I can't avoid the allocation.

Okay, that code makes way more sense

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Annoying that the code is duplicated between dom and xsl :/

zend_throw_error(NULL, "Function name must be passed as the first argument");
return;
}

Copy link
Member

Choose a reason for hiding this comment

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

Would the for loop below be more clear as:

for (i = fci.param_count; i > 0; i--) {

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I'll change it soon

@@ -132,7 +137,7 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
if (obj->stringval == NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment that this obj is the last element of the FILO stack and must correspond to a PHP function name?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack

Copy link
Member Author

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Thanks for the review.

Annoying that the code is duplicated between dom and xsl :/

Indeed. I factored it out already into a common file, on a wip branch that extends the features of the callbacks.

zend_throw_error(NULL, "Function name must be passed as the first argument");
return;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I'll change it soon

@@ -132,7 +137,7 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
if (obj->stringval == NULL) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Ack

@nielsdos nielsdos closed this in 20c9c4a Nov 2, 2023
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