diff options
author | Bob Weinand <bobwei9@hotmail.com> | 2015-08-24 12:28:35 +0100 |
---|---|---|
committer | Bob Weinand <bobwei9@hotmail.com> | 2015-08-24 12:28:35 +0100 |
commit | 6b3228fda452e3ff53b8b0bd87f74c6d5ceafa6d (patch) | |
tree | d76b0e0c8d959c757c0fe9f8eb4bff9a6f991b3d /sapi/phpdbg/phpdbg_list.c | |
parent | db5898c9e55b33c9378295a8a85aa863202996bc (diff) | |
download | php-git-6b3228fda452e3ff53b8b0bd87f74c6d5ceafa6d.tar.gz |
Fix oplog with eval()ed code
Diffstat (limited to 'sapi/phpdbg/phpdbg_list.c')
-rw-r--r-- | sapi/phpdbg/phpdbg_list.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c index f3181c0701..2424103480 100644 --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@ -31,6 +31,7 @@ #include "phpdbg_utils.h" #include "phpdbg_prompt.h" #include "php_streams.h" +#include "zend_exceptions.h" ZEND_EXTERN_MODULE_GLOBALS(phpdbg); @@ -318,6 +319,52 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) { return op_array; } +zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) { + zend_string *fake_name; + zend_op_array *op_array; + phpdbg_file_source *dataptr; + uint line; + char *bufptr, *endptr; + + if (PHPDBG_G(flags) & PHPDBG_IN_EVAL) { + return PHPDBG_G(compile_string)(source_string, filename); + } + + dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * Z_STRLEN_P(source_string)); + dataptr->buf = estrndup(Z_STRVAL_P(source_string), Z_STRLEN_P(source_string)); + dataptr->len = Z_STRLEN_P(source_string); + for (line = 0, bufptr = dataptr->buf - 1, endptr = dataptr->buf + dataptr->len; ++bufptr < endptr;) { + if (*bufptr == '\n') { + dataptr->line[++line] = (uint)(bufptr - dataptr->buf) + 1; + } + } + dataptr->lines = ++line; + dataptr->line[line] = endptr - dataptr->buf; + + op_array = PHPDBG_G(compile_string)(source_string, filename); + + if (op_array == NULL) { + efree(dataptr->buf); + efree(dataptr); + return NULL; + } + + fake_name = zend_strpprintf(0, "%s\0%p", filename, op_array->opcodes); + + dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line); + zend_hash_add_ptr(&PHPDBG_G(file_sources), fake_name, dataptr); + + dataptr->filename = estrndup(ZSTR_VAL(fake_name), ZSTR_LEN(fake_name)); + zend_string_release(fake_name); + + dataptr->op_array = *op_array; + if (dataptr->op_array.refcount) { + ++*dataptr->op_array.refcount; + } + + return op_array; +} + void phpdbg_free_file_source(zval *zv) { phpdbg_file_source *data = Z_PTR_P(zv); @@ -332,8 +379,10 @@ void phpdbg_free_file_source(zval *zv) { void phpdbg_init_list(void) { PHPDBG_G(compile_file) = zend_compile_file; + PHPDBG_G(compile_string) = zend_compile_string; zend_hash_init(&PHPDBG_G(file_sources), 1, NULL, (dtor_func_t) phpdbg_free_file_source, 0); zend_compile_file = phpdbg_compile_file; + zend_compile_string = phpdbg_compile_string; } void phpdbg_list_update(void) { |