diff options
author | Bob Weinand <bobwei9@hotmail.com> | 2016-12-22 00:42:05 +0100 |
---|---|---|
committer | Bob Weinand <bobwei9@hotmail.com> | 2016-12-22 00:42:05 +0100 |
commit | 5d7ce7274757451a536b3521debd8f89365b0349 (patch) | |
tree | 4d9cdf1cb2825b65acc4361e3371a8a7403b4df4 /sapi/phpdbg/phpdbg_prompt.c | |
parent | 3df43437fe76a2f396b77c1e00e8c68c5038d1ce (diff) | |
parent | 728502fc2978dcf9286ac049a5dbfa74187c9746 (diff) | |
download | php-git-5d7ce7274757451a536b3521debd8f89365b0349.tar.gz |
Merge branch 'PHP-7.1'
Diffstat (limited to 'sapi/phpdbg/phpdbg_prompt.c')
-rw-r--r-- | sapi/phpdbg/phpdbg_prompt.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 572e0a2ff7..ce8945ac6a 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -540,6 +540,7 @@ int phpdbg_compile_stdin(zend_string *code) { PHPDBG_G(exec_len) = sizeof("Standard input code") - 1; { /* remove leading ?> from source */ int i; + /* remove trailing data after zero byte, used for avoiding conflicts in eval()'ed code snippets */ zend_string *source_path = strpprintf(0, "Standard input code%c%p", 0, PHPDBG_G(ops)->opcodes); phpdbg_file_source *data = zend_hash_find_ptr(&PHPDBG_G(file_sources), source_path); dtor_func_t dtor = PHPDBG_G(file_sources).pDestructor; @@ -549,9 +550,6 @@ int phpdbg_compile_stdin(zend_string *code) { zend_hash_str_update_ptr(&PHPDBG_G(file_sources), "Standard input code", sizeof("Standard input code")-1, data); zend_string_release(source_path); - efree(data->filename); - data->filename = estrdup("Standard input code"); - for (i = 1; i <= data->lines; i++) { data->line[i] -= 2; } @@ -568,7 +566,10 @@ int phpdbg_compile(void) /* {{{ */ { zend_file_handle fh; char *buf; + char *start_line = NULL; size_t len; + size_t start_line_len; + int i; if (!PHPDBG_G(exec)) { phpdbg_error("inactive", "type=\"nocontext\"", "No execution context"); @@ -587,7 +588,10 @@ int phpdbg_compile(void) /* {{{ */ } case '\n': CG(start_lineno) = 2; - fh.handle.stream.mmap.len -= fh.handle.stream.mmap.buf - buf; + start_line_len = fh.handle.stream.mmap.buf - buf; + start_line = emalloc(start_line_len); + memcpy(start_line, buf, start_line_len); + fh.handle.stream.mmap.len -= start_line_len; end = fh.handle.stream.mmap.buf; } } while (fh.handle.stream.mmap.buf + 1 < end); @@ -595,6 +599,29 @@ int phpdbg_compile(void) /* {{{ */ PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE); + /* prepend shebang line to file_source */ + if (start_line) { + phpdbg_file_source *data = zend_hash_find_ptr(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename); + + dtor_func_t dtor = PHPDBG_G(file_sources).pDestructor; + PHPDBG_G(file_sources).pDestructor = NULL; + zend_hash_del(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename); + PHPDBG_G(file_sources).pDestructor = dtor; + + data = erealloc(data, sizeof(phpdbg_file_source) + sizeof(uint) * ++data->lines); + memmove(data->line + 1, data->line, sizeof(uint) * data->lines); + data->line[0] = 0; + data->buf = erealloc(data->buf, data->len + start_line_len); + memmove(data->buf + start_line_len, data->buf, data->len * sizeof(uint)); + memcpy(data->buf, start_line, start_line_len); + efree(start_line); + data->len += start_line_len; + for (i = 1; i <= data->lines; i++) { + data->line[i] += start_line_len; + } + zend_hash_update_ptr(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename, data); + } + fh.handle.stream.mmap.buf = buf; fh.handle.stream.mmap.len = len; zend_destroy_file_handle(&fh); |