com php-src: Fixed issue getting executable lines from custom wrappers: NEWS sapi/phpdbg/phpdbg_list.c sapi/phpdbg/tests/phpdbg
_get_executable_stream_wrapper.inc sapi/phpdbg/test s/phpdbg_get_executable_stream_wrapper.phpt
| From: | Bob Weinand | Date: | Tue, 06 Dec 2016 17:29:48 +0000 |
| Subject: | com php-src: Fixed issue getting executable lines from custom wrappers: NEWS sapi/phpdbg/phpdbg_list.c sapi/phpdbg/tests/phpdbg _get_executable_stream_wrapper.inc sapi/phpdbg/test s/phpdbg_get_executable_stream_wrapper.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-96226@lists.php.net to get a copy of this message | ||
Commit: 7e12b5da712f603d4ff68c378c0b1f06dcc495db
Author: Bob Weinand <bobwei9@hotmail.com> Tue, 6 Dec 2016 18:27:31 +0100
Parents: fee5c049a8190289ddbb39c71f2422031d0d12e3
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7e12b5da712f603d4ff68c378c0b1f06dcc495db
Log:
Fixed issue getting executable lines from custom wrappers
See also krakjoe/phpdbg#161
Bugs:
https://bugs.php.net/161
Changed paths:
M NEWS
M sapi/phpdbg/phpdbg_list.c
A sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.inc
A sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
Diff:
diff --git a/NEWS b/NEWS
index 901d9f5..0222f56 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ PHP NEWS
- Phpdbg:
. Fixed bug #73615 (phpdbg without option never load .phpdbginit at startup).
(Bob)
+ . Fixed issue getting executable lines from custom wrappers. (Bob)
08 Dec 2016 PHP 7.0.14
diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c
index b0bb157..1b70039 100644
--- a/sapi/phpdbg/phpdbg_list.c
+++ b/sapi/phpdbg/phpdbg_list.c
@@ -235,15 +235,16 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
phpdbg_file_source data, *dataptr;
zend_file_handle fake;
zend_op_array *ret;
- char *filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) :
file->filename);
+ char *filename;
uint line;
char *bufptr, *endptr;
- char resolved_path_buf[MAXPATHLEN];
if (zend_stream_fixup(file, &bufptr, &data.len) == FAILURE) {
return PHPDBG_G(compile_file)(file, type);
}
+ filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename);
+
data.buf = emalloc(data.len + ZEND_MMAP_AHEAD + 1);
if (data.len > 0) {
memcpy(data.buf, bufptr, data.len);
@@ -261,9 +262,6 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
fake.opened_path = file->opened_path;
*(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * data.len)) = data;
- if (VCWD_REALPATH(filename, resolved_path_buf)) {
- filename = resolved_path_buf;
- }
for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) {
if (*bufptr == '\n') {
@@ -323,6 +321,8 @@ 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));
ZEND_ASSERT(dataptr != NULL);
diff --git a/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.inc
b/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.inc
new file mode 100644
index 0000000..4f41557
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.inc
@@ -0,0 +1,6 @@
+<?php
+
+function foo()
+{
+ return '<result>'; // line 5 is executable
+}
diff --git a/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
b/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
new file mode 100644
index 0000000..0ddbd6f
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_get_executable_stream_wrapper.phpt
@@ -0,0 +1,84 @@
+--TEST--
+Getting executable lines from custom wrappers
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> array(1) {
+ [5]=>
+ int(0)
+}
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+/**
+ * This example demonstrates how phpdbg_get_executable() behaves differently
+ * when passed the 'files' option vs without, in the face of some mild abuse
+ * of stream wrappers.
+ */
+
+/**
+ * First, we define a stream wrapper that simply maps to a real file on disk.
+ */
+final class StreamWrapper
+{
+ public function stream_open(
+ string $path,
+ string $mode,
+ int $options = 0,
+ string &$openedPath = null
+ ) : bool {
+ if ($mode[0] !== 'r') {
+ return false;
+ }
+
+ list($scheme, $path) = explode('://', $path, 2);
+
+ $stream = \fopen($path, $mode);
+
+ if ($stream === false) {
+ return false;
+ }
+
+ $this->stream = $stream;
+
+ /**
+ * The $openedPath reference variable is assigned, indicating the
+ * *actual* path that was opened. This affects the behaviour of
+ * constants like __FILE__.
+ */
+ $openedPath = \realpath($path);
+
+ return true;
+ }
+
+ public function stream_read(int $count) : string { return \fread($this->stream, $count); }
+ public function stream_close() : bool { return \fclose($this->stream); }
+ public function stream_eof() : bool { return \feof($this->stream); }
+ public function stream_stat() { return \fstat($this->stream); }
+
+ private $stream = false;
+}
+
+stream_wrapper_register('wrapper', StreamWrapper::class);
+
+/**
+ * Next, we include a PHP file that contains executable lines, via the stream
+ * wrapper.
+ */
+$filename = __DIR__ . '/phpdbg_get_executable_stream_wrapper.inc';
+require 'wrapper://' . $filename;
+
+/**
+ * If we call phpdbg_get_executable() and pass no options, the realpath of the
+ * included file is present in the array, but indicates no executable lines.
+ */
+$x = phpdbg_get_executable();
+
+// We expect [5 => 0], but got an empty array ...
+var_dump($x[$filename]);
+
+?>