Skip to content

Commit a7d856d

Browse files
committed
ext/readline: fix global readline vars when updating rl_line_buffer.
if the new value was larger, rl_line_buffer_length was never updated. neither was rl_end (on unixes). close GH-15120
1 parent 177fd88 commit a7d856d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ PHP NEWS
5050
. Fixed bug GH-15094 (php_random_default_engine() is not C++ conforming).
5151
(cmb)
5252

53+
- Readline:
54+
. Fixed readline_info, rl_line_buffer_length/rl_len globals on update.
55+
(David Carlier)
56+
5357
- Standard:
5458
. Fix references in request_parse_body() options array. (nielsdos)
5559
. Add RoundingMode enum. (timwolla, saki)

ext/readline/readline.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,24 @@ PHP_FUNCTION(readline_info)
183183
if (zend_string_equals_literal_ci(what,"line_buffer")) {
184184
oldstr = rl_line_buffer;
185185
if (value) {
186-
/* XXX if (rl_line_buffer) free(rl_line_buffer); */
187186
if (!try_convert_to_string(value)) {
188187
RETURN_THROWS();
189188
}
190-
rl_line_buffer = strdup(Z_STRVAL_P(value));
189+
#ifndef PHP_WIN32
190+
if (strlen(oldstr) < Z_STRLEN_P(value)) {
191+
rl_extend_line_buffer(Z_STRLEN_P(value) + 1);
192+
}
193+
memcpy(rl_line_buffer, Z_STRVAL_P(value), Z_STRLEN_P(value) + 1);
194+
rl_end = Z_STRLEN_P(value);
195+
#else
196+
char *tmp = strdup(Z_STRVAL_P(value));
197+
if (tmp) {
198+
if (rl_line_buffer) {
199+
free(rl_line_buffer);
200+
}
201+
rl_line_buffer = tmp;
202+
}
203+
#endif
191204
}
192205
RETVAL_STRING(SAFE_STRING(oldstr));
193206
} else if (zend_string_equals_literal_ci(what, "point")) {

0 commit comments

Comments
 (0)