File tree 3 files changed +22
-2
lines changed
3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ PHP NEWS
24
24
- PDO:
25
25
. Fixed memory leak of `setFetchMode()`. (SakiTakamachi)
26
26
27
+ - Readline:
28
+ . Fixed UAF with readline_info(). (David Carlier)
29
+
27
30
- Reflection:
28
31
. Fixed the name of the second parameter of
29
32
ReflectionClass::resetAsLazyGhost(). (Arnaud)
Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ PHP_FUNCTION(readline_info)
181
181
add_assoc_long (return_value ,"attempted_completion_over" ,rl_attempted_completion_over );
182
182
} else {
183
183
if (zend_string_equals_literal_ci (what ,"line_buffer" )) {
184
- oldstr = rl_line_buffer ;
184
+ oldstr = strdup ( rl_line_buffer ? rl_line_buffer : "" ) ;
185
185
if (value ) {
186
186
if (!try_convert_to_string (value )) {
187
187
RETURN_THROWS ();
@@ -191,7 +191,8 @@ PHP_FUNCTION(readline_info)
191
191
rl_line_buffer = malloc (Z_STRLEN_P (value ) + 1 );
192
192
} else if (strlen (oldstr ) < Z_STRLEN_P (value )) {
193
193
rl_extend_line_buffer (Z_STRLEN_P (value ) + 1 );
194
- oldstr = rl_line_buffer ;
194
+ free (oldstr );
195
+ oldstr = strdup (rl_line_buffer ? rl_line_buffer : "" );
195
196
}
196
197
memcpy (rl_line_buffer , Z_STRVAL_P (value ), Z_STRLEN_P (value ) + 1 );
197
198
#else
@@ -208,6 +209,7 @@ PHP_FUNCTION(readline_info)
208
209
#endif
209
210
}
210
211
RETVAL_STRING (SAFE_STRING (oldstr ));
212
+ free (oldstr );
211
213
} else if (zend_string_equals_literal_ci (what , "point" )) {
212
214
RETVAL_LONG (rl_point );
213
215
#ifndef PHP_WIN32
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-16812 readline_info(): UAF
3
+ --EXTENSIONS--
4
+ readline
5
+ --SKIPIF--
6
+ <?php
7
+ if (getenv ('SKIP_REPEAT ' )) die ("skip readline has global state " );
8
+ ?>
9
+ --FILE--
10
+ <?php
11
+ readline_write_history (NULL );
12
+ var_dump (readline_info ('line_buffer ' , 'test ' ));
13
+ ?>
14
+ --EXPECT--
15
+ string(0) ""
You can’t perform that action at this time.
0 commit comments