Skip to content
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

Fix GH-16812: UAF on readline_info() after readline_write_history() c… #16813

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/readline/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ PHP_FUNCTION(readline_info)
if (rl_line_buffer) {
free(rl_line_buffer);
cmb69 marked this conversation as resolved.
Show resolved Hide resolved
}
rl_line_buffer = tmp;
oldstr = rl_line_buffer = tmp;
cmb69 marked this conversation as resolved.
Show resolved Hide resolved
}
#endif
#if !defined(PHP_WIN32)
Expand Down
19 changes: 19 additions & 0 deletions ext/readline/tests/gh16812.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-16812 readline_info(): UAF
--EXTENSIONS--
readline
--SKIPIF--
<?php
if (READLINE_LIB != "libedit") die("skip libedit only");
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
die('skip not for windows');
}
cmb69 marked this conversation as resolved.
Show resolved Hide resolved
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(4) "test"
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look right; I think readline_info() is supposed to return the old line_buffer which should be an empty string.