-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-16812: UAF on readline_info() after readline_write_history() c… #16813
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
5 commits
Select commit
Hold shift + click to select a range
f16a9c7
Fix GH-16812: UAF on readline_info() after readline_write_history() c…
devnexen df81263
add test
devnexen 1db70c0
changes from feedback, copying original before hand instead.
devnexen 4650692
enable the test on windows
devnexen ca32a24
enable for the old readline lib too
devnexen 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,7 @@ PHP_FUNCTION(readline_info) | |
add_assoc_long(return_value,"attempted_completion_over",rl_attempted_completion_over); | ||
} else { | ||
if (zend_string_equals_literal_ci(what,"line_buffer")) { | ||
oldstr = rl_line_buffer; | ||
oldstr = strdup(rl_line_buffer ? rl_line_buffer : ""); | ||
if (value) { | ||
if (!try_convert_to_string(value)) { | ||
RETURN_THROWS(); | ||
|
@@ -191,7 +191,8 @@ PHP_FUNCTION(readline_info) | |
rl_line_buffer = malloc(Z_STRLEN_P(value) + 1); | ||
} else if (strlen(oldstr) < Z_STRLEN_P(value)) { | ||
rl_extend_line_buffer(Z_STRLEN_P(value) + 1); | ||
oldstr = rl_line_buffer; | ||
free(oldstr); | ||
oldstr = strdup(rl_line_buffer ? rl_line_buffer : ""); | ||
Comment on lines
+194
to
+195
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. Since we touch this code path (libreadline only), we should also run the test against libreadline. |
||
} | ||
memcpy(rl_line_buffer, Z_STRVAL_P(value), Z_STRLEN_P(value) + 1); | ||
#else | ||
|
@@ -208,6 +209,7 @@ PHP_FUNCTION(readline_info) | |
#endif | ||
} | ||
RETVAL_STRING(SAFE_STRING(oldstr)); | ||
free(oldstr); | ||
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. Ah, right, good idea! |
||
} else if (zend_string_equals_literal_ci(what, "point")) { | ||
RETVAL_LONG(rl_point); | ||
#ifndef PHP_WIN32 | ||
|
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,15 @@ | ||
--TEST-- | ||
GH-16812 readline_info(): UAF | ||
--EXTENSIONS-- | ||
readline | ||
--SKIPIF-- | ||
<?php | ||
if (getenv('SKIP_REPEAT')) die("skip readline has global state"); | ||
?> | ||
--FILE-- | ||
<?php | ||
readline_write_history(NULL); | ||
var_dump(readline_info('line_buffer', 'test')); | ||
?> | ||
--EXPECT-- | ||
string(0) "" |
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.
The
strdup("")
doesn't seem to be necessary (that's already handled bySAFE_STRING()
. It's not wrong though, and performance is likely irrelevant here.