-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-16414: zend_test.observer.observe_function_names may segfault #16438
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
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
GH-16414 (zend_test.observer.observe_function_names may segfault) | ||
--EXTENSIONS-- | ||
zend_test | ||
--INI-- | ||
zend_test.observer.enabled=0 | ||
--FILE-- | ||
<?php | ||
function bar() {} | ||
var_dump(ini_set("zend_test.observer.observe_function_names", "bar")); | ||
?> | ||
--EXPECT-- | ||
bool(false) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't understand this.
ZEND_OBSERVER_DATA()
expands to&RUN_TIME_CACHE(op_array)[handle]
, which cannot beNULL
(except forRUN_TIME_CACHE(op_array) == NULL && handle == 0
, which is undefined behavior). Removing these two conditions still makes the test pass. Should this have dereferenced the pointer?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.
Actually, it probably must handle
ZEND_OBSERVER_NOT_OBSERVED
andZEND_OBSERVER_NONE_OBSERVED
. But I forgot about the details of this api.Uh oh!
There was an error while loading. Please reload this page.
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.
@iluuu1994 The value is NULL if the observer has not been initialized yet. It's non-NULL once the init handler ran, assigning a specific handler or one of these two constants. Here we only care about initialized.
But it seems to be missing a dereference, yes. (In PHP 8.3 and before it evaluated to the first value. Hence I missed this.)
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.
I'll have a look as soon as possible.
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.
@iluuu1994, this PR targets PHP-8.4; the definition of
ZEND_OBSERVER_DATA()
has changed there:php-src/Zend/zend_observer.h
Lines 39 to 40 in 5892991
That part is needed if
zend_test.observer.enabled=1
upfront (default for our Circle CI job).@bwoebi, when running the test with
zend_test.observer.enabled=1
,ZEND_OBSERVER_DATA(func)
isNULL
for me.Uh oh!
There was an error while loading. Please reload this page.
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.
It's because
RUN_TIME_CACHE(&func->common)
isNULL
, so doing pointer arithmetics on it is UB. In that case, I think we should check whetherRUN_TIME_CACHE(&func->common)
is set. Note that you're lucky here, if observer had a higher handle, this check would break.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.
Ah, thank you! I'll have a closer look again, and might actually go with the hash table.