Skip to content

Commit f07d66c

Browse files
committed
Fix PHPDBG compilation (phpdbg_parse_variable may modify the content of input)
1 parent 92bc94e commit f07d66c

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

sapi/phpdbg/phpdbg_cmd.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,6 @@ PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async
740740
PHPDBG_API char *phpdbg_read_input(const char *buffered) /* {{{ */
741741
{
742742
char buf[PHPDBG_MAX_CMD];
743-
char *cmd = NULL;
744743
char *buffer = NULL;
745744

746745
if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) != PHPDBG_IS_STOPPING) {
@@ -755,11 +754,12 @@ PHPDBG_API char *phpdbg_read_input(const char *buffered) /* {{{ */
755754
#endif
756755
{
757756
phpdbg_write("prompt", "", "%s", phpdbg_get_prompt());
758-
phpdbg_consume_stdin_line(cmd = buf);
757+
phpdbg_consume_stdin_line(buf);
758+
buffer = estrdup(buf);
759759
}
760760
#ifdef HAVE_PHPDBG_READLINE
761761
else {
762-
cmd = readline(phpdbg_get_prompt());
762+
char *cmd = readline(phpdbg_get_prompt());
763763
PHPDBG_G(last_was_newline) = 1;
764764

765765
if (!cmd) {
@@ -768,19 +768,13 @@ PHPDBG_API char *phpdbg_read_input(const char *buffered) /* {{{ */
768768
}
769769

770770
add_history(cmd);
771+
buffer = estrdup(cmd);
772+
free(cmd);
771773
}
772774
#endif
773775
} else {
774-
cmd = buffered;
776+
buffer = estrdup(buffered);
775777
}
776-
777-
buffer = estrdup(cmd);
778-
779-
#ifdef HAVE_PHPDBG_READLINE
780-
if (!buffered && cmd && !(PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && isatty(PHPDBG_G(io)[PHPDBG_STDIN].fd)) {
781-
free(cmd);
782-
}
783-
#endif
784778
}
785779

786780
if (buffer && isspace(*buffer)) {

sapi/phpdbg/phpdbg_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,11 @@ static int phpdbg_parse_variable_arg_wrapper(char *name, size_t len, char *keyna
424424
return callback(name, len, keyname, keylen, parent, zv);
425425
}
426426

427-
PHPDBG_API int phpdbg_parse_variable(const char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent) {
427+
PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent) {
428428
return phpdbg_parse_variable_with_arg(input, len, parent, i, (phpdbg_parse_var_with_arg_func) phpdbg_parse_variable_arg_wrapper, NULL, silent, callback);
429429
}
430430

431-
PHPDBG_API int phpdbg_parse_variable_with_arg(const char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg) {
431+
PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg) {
432432
int ret = FAILURE;
433433
zend_bool new_index = 1;
434434
char *last_index = NULL;

sapi/phpdbg/phpdbg_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ char *phpdbg_get_property_key(char *key);
8686
typedef int (*phpdbg_parse_var_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv);
8787
typedef int (*phpdbg_parse_var_with_arg_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, void *arg);
8888

89-
PHPDBG_API int phpdbg_parse_variable(const char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent);
90-
PHPDBG_API int phpdbg_parse_variable_with_arg(const char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg);
89+
PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent);
90+
PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg);
9191

9292
int phpdbg_is_auto_global(char *name, int len);
9393

0 commit comments

Comments
 (0)