summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2016-12-22 00:38:47 +0100
committerBob Weinand <bobwei9@hotmail.com>2016-12-22 00:39:24 +0100
commit3b2b080cbcdcadb97f9dd2db1a6e9e4200c34023 (patch)
treecb4079d14adcd589e9caadef6329bf34165b419d
parentc41826d1e626962621805eab650b1fcc2f1f49d8 (diff)
downloadphp-git-3b2b080cbcdcadb97f9dd2db1a6e9e4200c34023.tar.gz
Fixed bug #73704 (phpdbg shows the wrong line in files with shebang)
-rw-r--r--NEWS1
-rw-r--r--sapi/phpdbg/phpdbg_list.c12
-rw-r--r--sapi/phpdbg/phpdbg_list.h1
-rw-r--r--sapi/phpdbg/phpdbg_prompt.c35
-rw-r--r--sapi/phpdbg/tests/bug73704.phpt27
5 files changed, 62 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index 53186e79ce..002fec717c 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,7 @@ PHP NEWS
. Fixed bug #73615 (phpdbg without option never load .phpdbginit at startup).
(Bob)
. Fixed issue getting executable lines from custom wrappers. (Bob)
+ . Fixed bug #73704 (phpdbg shows the wrong line in files with shebang). (Bob)
- Reflection:
. Fixed bug #46103 (ReflectionObject memory leak). (Nikita)
diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c
index 1b70039fda..34e9187f52 100644
--- a/sapi/phpdbg/phpdbg_list.c
+++ b/sapi/phpdbg/phpdbg_list.c
@@ -250,7 +250,6 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
memcpy(data.buf, bufptr, data.len);
}
memset(data.buf + data.len, 0, ZEND_MMAP_AHEAD + 1);
- data.filename = filename;
data.line[0] = 0;
memset(&fake, 0, sizeof(fake));
@@ -283,10 +282,9 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
return NULL;
}
- dataptr->filename = estrdup(dataptr->filename);
dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line);
- zend_hash_str_add_ptr(&PHPDBG_G(file_sources), filename, strlen(filename), dataptr);
- phpdbg_resolve_pending_file_break(filename);
+ zend_hash_add_ptr(&PHPDBG_G(file_sources), ret->filename, dataptr);
+ phpdbg_resolve_pending_file_break(ZSTR_VAL(ret->filename));
fake.opened_path = NULL;
zend_file_handle_dtor(&fake);
@@ -321,9 +319,7 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) {
return NULL;
}
- filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename);
-
- dataptr = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), filename, strlen(filename));
+ dataptr = zend_hash_find_ptr(&PHPDBG_G(file_sources), op_array->filename);
ZEND_ASSERT(dataptr != NULL);
dataptr->op_array = *op_array;
@@ -370,7 +366,6 @@ zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) {
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;
@@ -387,7 +382,6 @@ void phpdbg_free_file_source(zval *zv) {
if (data->buf) {
efree(data->buf);
}
- efree(data->filename);
destroy_op_array(&data->op_array);
diff --git a/sapi/phpdbg/phpdbg_list.h b/sapi/phpdbg/phpdbg_list.h
index c011b9598a..62ded66cf0 100644
--- a/sapi/phpdbg/phpdbg_list.h
+++ b/sapi/phpdbg/phpdbg_list.h
@@ -42,7 +42,6 @@ void phpdbg_init_list(void);
void phpdbg_list_update(void);
typedef struct {
- char *filename;
char *buf;
size_t len;
#if HAVE_MMAP
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index 4ee27d1beb..450e57d02e 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -544,6 +544,7 @@ int phpdbg_compile_stdin(zend_string *code) {
PHPDBG_G(exec_len) = 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, "-%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;
@@ -553,9 +554,6 @@ int phpdbg_compile_stdin(zend_string *code) {
zend_hash_str_update_ptr(&PHPDBG_G(file_sources), "-", 1, data);
zend_string_release(source_path);
- efree(data->filename);
- data->filename = estrdup("-");
-
for (i = 1; i <= data->lines; i++) {
data->line[i] -= 2;
}
@@ -572,7 +570,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");
@@ -591,7 +592,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);
@@ -599,6 +603,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);
diff --git a/sapi/phpdbg/tests/bug73704.phpt b/sapi/phpdbg/tests/bug73704.phpt
new file mode 100644
index 0000000000..a3ee92b126
--- /dev/null
+++ b/sapi/phpdbg/tests/bug73704.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #73704 (phpdbg shows the wrong line in files with shebang)
+--PHPDBG--
+list 6
+b 4
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> 00001: #!/usr/bin/env php
+ 00002: <?php
+ 00003:
+ 00004: echo 1;
+ 00005:
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 1;
+ 00005:
+prompt> 1
+[Script ended normally]
+prompt>
+--FILE--
+#!/usr/bin/env php
+<?php
+
+echo 1;