Skip to content

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jan 5, 2025

Allocating a string zval to let zend_call_function() do the same thing is slightly pointless

HashTable *params_ht = NULL;
zend_function *user_fn = zend_hash_str_find_ptr(EG(function_table), lc_name, name->len);
if (user_fn == NULL) {
// TODO Debug for unknown function?
Copy link
Member

Choose a reason for hiding this comment

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

Leak on lc_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.

Ah indeed, I don't really know how to write PHPDBG tests, but that would be a good one to cover

Copy link
Member

Choose a reason for hiding this comment

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

See sapi/phpdbg/tests, it has a PHPDBG section. https://qa.php.net/phpt_details.php#phpdbg_section

@Girgias Girgias force-pushed the phpdbg-call-user-fn-directly branch from 9c81fb7 to 4e36429 Compare January 6, 2025 16:55
@Girgias
Copy link
Member Author

Girgias commented Jan 6, 2025

I "fixed" the leak in a better way digging at the code, but this whole thing is broken as just registering a function will cause a use after free, moreover, triggering the actual call to the registered function is still eliding me.

Considering the R option to register a function is not documented, seemingly pointless, and broken, I will do another PR just to rip this out.

nielsdos and others added 3 commits January 6, 2025 18:42
Internal function won't need their refcount increased as they outlive
the debugger session, and userland functions won't be unloaded either.
So no refcount management is necessary for registered functions.
Allocating a string zval to let zend_call_function() do the same thing is slightly pointless
@Girgias Girgias force-pushed the phpdbg-call-user-fn-directly branch from 4e36429 to 3034f07 Compare January 6, 2025 18:43
Copy link
Member

@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.

One nit, ok otherwise LGTM

@nielsdos
Copy link
Member

nielsdos commented Jan 6, 2025

I propose that when this is merged "fix-15981" gets backported to 8.3+.

@Girgias
Copy link
Member Author

Girgias commented Jan 6, 2025

I propose that when this is merged "fix-15981" gets backported to 8.3+.

Agreed, that makes sense to me too

@Girgias Girgias merged commit e2e7b46 into php:master Jan 6, 2025
10 checks passed
@Girgias Girgias deleted the phpdbg-call-user-fn-directly branch January 6, 2025 20:17
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