Skip to content

Commit 5d7ce72

Browse files
committed
Merge branch 'PHP-7.1'
2 parents 3df4343 + 728502f commit 5d7ce72

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

sapi/phpdbg/phpdbg.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ static void php_phpdbg_destroy_file_source(zval *data) /* {{{ */
128128
if (source->buf) {
129129
efree(source->buf);
130130
}
131-
efree(source->filename);
132131
efree(source);
133132
} /* }}} */
134133

sapi/phpdbg/phpdbg_list.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
251251
memcpy(data.buf, bufptr, data.len);
252252
}
253253
memset(data.buf + data.len, 0, ZEND_MMAP_AHEAD + 1);
254-
data.filename = filename;
255254
data.line[0] = 0;
256255

257256
memset(&fake, 0, sizeof(fake));
@@ -284,10 +283,9 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
284283
return NULL;
285284
}
286285

287-
dataptr->filename = estrdup(dataptr->filename);
288286
dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line);
289-
zend_hash_str_add_ptr(&PHPDBG_G(file_sources), filename, strlen(filename), dataptr);
290-
phpdbg_resolve_pending_file_break(filename);
287+
zend_hash_add_ptr(&PHPDBG_G(file_sources), ret->filename, dataptr);
288+
phpdbg_resolve_pending_file_break(ZSTR_VAL(ret->filename));
291289

292290
fake.opened_path = NULL;
293291
zend_file_handle_dtor(&fake);
@@ -322,9 +320,7 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) {
322320
return NULL;
323321
}
324322

325-
filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename);
326-
327-
dataptr = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), filename, strlen(filename));
323+
dataptr = zend_hash_find_ptr(&PHPDBG_G(file_sources), op_array->filename);
328324
ZEND_ASSERT(dataptr != NULL);
329325

330326
dataptr->op_array = *op_array;
@@ -371,7 +367,6 @@ zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) {
371367
dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line);
372368
zend_hash_add_ptr(&PHPDBG_G(file_sources), fake_name, dataptr);
373369

374-
dataptr->filename = estrndup(ZSTR_VAL(fake_name), ZSTR_LEN(fake_name));
375370
zend_string_release(fake_name);
376371

377372
dataptr->op_array = *op_array;

sapi/phpdbg/phpdbg_list.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ void phpdbg_init_list(void);
4242
void phpdbg_list_update(void);
4343

4444
typedef struct {
45-
char *filename;
4645
char *buf;
4746
size_t len;
4847
#if HAVE_MMAP

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ int phpdbg_compile_stdin(zend_string *code) {
540540
PHPDBG_G(exec_len) = sizeof("Standard input code") - 1;
541541
{ /* remove leading ?> from source */
542542
int i;
543+
/* remove trailing data after zero byte, used for avoiding conflicts in eval()'ed code snippets */
543544
zend_string *source_path = strpprintf(0, "Standard input code%c%p", 0, PHPDBG_G(ops)->opcodes);
544545
phpdbg_file_source *data = zend_hash_find_ptr(&PHPDBG_G(file_sources), source_path);
545546
dtor_func_t dtor = PHPDBG_G(file_sources).pDestructor;
@@ -549,9 +550,6 @@ int phpdbg_compile_stdin(zend_string *code) {
549550
zend_hash_str_update_ptr(&PHPDBG_G(file_sources), "Standard input code", sizeof("Standard input code")-1, data);
550551
zend_string_release(source_path);
551552

552-
efree(data->filename);
553-
data->filename = estrdup("Standard input code");
554-
555553
for (i = 1; i <= data->lines; i++) {
556554
data->line[i] -= 2;
557555
}
@@ -568,7 +566,10 @@ int phpdbg_compile(void) /* {{{ */
568566
{
569567
zend_file_handle fh;
570568
char *buf;
569+
char *start_line = NULL;
571570
size_t len;
571+
size_t start_line_len;
572+
int i;
572573

573574
if (!PHPDBG_G(exec)) {
574575
phpdbg_error("inactive", "type=\"nocontext\"", "No execution context");
@@ -587,14 +588,40 @@ int phpdbg_compile(void) /* {{{ */
587588
}
588589
case '\n':
589590
CG(start_lineno) = 2;
590-
fh.handle.stream.mmap.len -= fh.handle.stream.mmap.buf - buf;
591+
start_line_len = fh.handle.stream.mmap.buf - buf;
592+
start_line = emalloc(start_line_len);
593+
memcpy(start_line, buf, start_line_len);
594+
fh.handle.stream.mmap.len -= start_line_len;
591595
end = fh.handle.stream.mmap.buf;
592596
}
593597
} while (fh.handle.stream.mmap.buf + 1 < end);
594598
}
595599

596600
PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE);
597601

602+
/* prepend shebang line to file_source */
603+
if (start_line) {
604+
phpdbg_file_source *data = zend_hash_find_ptr(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename);
605+
606+
dtor_func_t dtor = PHPDBG_G(file_sources).pDestructor;
607+
PHPDBG_G(file_sources).pDestructor = NULL;
608+
zend_hash_del(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename);
609+
PHPDBG_G(file_sources).pDestructor = dtor;
610+
611+
data = erealloc(data, sizeof(phpdbg_file_source) + sizeof(uint) * ++data->lines);
612+
memmove(data->line + 1, data->line, sizeof(uint) * data->lines);
613+
data->line[0] = 0;
614+
data->buf = erealloc(data->buf, data->len + start_line_len);
615+
memmove(data->buf + start_line_len, data->buf, data->len * sizeof(uint));
616+
memcpy(data->buf, start_line, start_line_len);
617+
efree(start_line);
618+
data->len += start_line_len;
619+
for (i = 1; i <= data->lines; i++) {
620+
data->line[i] += start_line_len;
621+
}
622+
zend_hash_update_ptr(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename, data);
623+
}
624+
598625
fh.handle.stream.mmap.buf = buf;
599626
fh.handle.stream.mmap.len = len;
600627
zend_destroy_file_handle(&fh);

sapi/phpdbg/tests/bug73704.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #73704 (phpdbg shows the wrong line in files with shebang)
3+
--PHPDBG--
4+
list 6
5+
b 4
6+
r
7+
c
8+
q
9+
--EXPECTF--
10+
[Successful compilation of %s]
11+
prompt> 00001: #!/usr/bin/env php
12+
00002: <?php
13+
00003:
14+
00004: echo 1;
15+
00005:
16+
prompt> [Breakpoint #0 added at %s:4]
17+
prompt> [Breakpoint #0 at %s:4, hits: 1]
18+
>00004: echo 1;
19+
00005:
20+
prompt> 1
21+
[Script ended normally]
22+
prompt>
23+
--FILE--
24+
#!/usr/bin/env php
25+
<?php
26+
27+
echo 1;

0 commit comments

Comments
 (0)