-
Notifications
You must be signed in to change notification settings - Fork 171
Prevent func_hash_counters underflow #91
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
base: master
Are you sure you want to change the base?
Changes from all commits
5a6c4e6
620597b
34c830c
7e06de7
aed2750
62aaf93
c89998f
df9aace
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,16 +84,13 @@ static zend_always_inline zend_string *hp_get_trace_callback(zend_string *functi | |
| callback = (hp_trace_callback*)zend_hash_find_ptr(XHPROF_G(trace_callbacks), function_name); | ||
| if (callback) { | ||
| trace_name = (*callback)(function_name, data); | ||
| } else { | ||
| return function_name; | ||
| zend_string_release(function_name); | ||
| return trace_name; | ||
| } | ||
| } else { | ||
| return function_name; | ||
| } | ||
|
|
||
| zend_string_release(function_name); | ||
|
|
||
| return trace_name; | ||
|
|
||
| /* No callback found, return the original function_name */ | ||
| return function_name; | ||
| } | ||
|
|
||
| static zend_always_inline hp_entry_t *hp_fast_alloc_hprof_entry() | ||
|
|
@@ -114,6 +111,7 @@ static zend_always_inline void hp_fast_free_hprof_entry(hp_entry_t *p) | |
| { | ||
| if (p->name_hprof != NULL) { | ||
| zend_string_release(p->name_hprof); | ||
| p->name_hprof = NULL; /* Prevent double-free if entry is reused */ | ||
| } | ||
|
|
||
| /* we use/overload the prev_hprof field in the structure to link entries in | ||
|
|
@@ -161,7 +159,13 @@ static zend_always_inline int begin_profiling(zend_string *root_symbol, zend_exe | |
| } else { | ||
| #if PHP_VERSION_ID >= 80000 | ||
| hp_entry_t *cur_entry = hp_fast_alloc_hprof_entry(); | ||
| (cur_entry)->name_hprof = zend_string_copy((*(entries))->name_hprof); | ||
| /* Check if entries is not NULL before dereferencing */ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously assumed |
||
| if (*(entries) != NULL) { | ||
| (cur_entry)->name_hprof = zend_string_copy((*(entries))->name_hprof); | ||
| } else { | ||
| /* If this is the first call and it's ignored, use the function name */ | ||
| (cur_entry)->name_hprof = zend_string_copy(function_name); | ||
| } | ||
| (cur_entry)->prev_hprof = (*(entries)); | ||
| (cur_entry)->is_trace = 0; | ||
| (*(entries)) = (cur_entry); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -924,7 +924,7 @@ void hp_mode_hier_endfn_cb(hp_entry_t **entries) | |
|
|
||
| #if PHP_VERSION_ID >= 80000 | ||
| if (top->is_trace == 0) { | ||
| XHPROF_G(func_hash_counters[top->hash_code])--; | ||
| /* For ignored functions, don't decrement hash counter since it was never incremented */ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously:
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, this should only affect PHP 8.4? |
||
| return; | ||
| } | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously: