Skip to content

Commit a982125

Browse files
committed
Try to fix phpdbg + opcache compatibility
1 parent 79ff867 commit a982125

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

sapi/phpdbg/phpdbg_list.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,29 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
237237
zend_op_array *ret;
238238
uint32_t line;
239239
char *bufptr, *endptr;
240-
int size;
240+
size_t len;
241+
242+
/* Copy file contents before calling original compile_file,
243+
* as it may invalidate the file handle. */
244+
if (zend_stream_fixup(file, &bufptr, &len) == FAILURE) {
245+
if (type == ZEND_REQUIRE) {
246+
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file->filename);
247+
zend_bailout();
248+
} else {
249+
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file->filename);
250+
}
251+
}
252+
253+
data.buf = estrndup(bufptr, len);
254+
data.len = len;
241255

242256
ret = PHPDBG_G(compile_file)(file, type);
243257
if (ret == NULL) {
258+
efree(data.buf);
244259
return ret;
245260
}
246261

247-
if (file->type == ZEND_HANDLE_MAPPED) {
248-
data.len = file->handle.stream.mmap.len;
249-
data.buf = emalloc(data.len + 1);
250-
memcpy(data.buf, file->handle.stream.mmap.buf, data.len);
251-
} else {
252-
if (file->type == ZEND_HANDLE_FILENAME) {
253-
zend_stream_open(file->filename, file);
254-
}
255-
256-
size = file->handle.stream.fsizer(file->handle.stream.handle);
257-
data.buf = emalloc(size + 1);
258-
data.len = file->handle.stream.reader(file->handle.stream.handle, data.buf, size);
259-
}
260-
261-
memset(data.buf + data.len, 0, 1);
262-
262+
data.buf[data.len] = '\0';
263263
data.line[0] = 0;
264264
*(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint32_t) * data.len)) = data;
265265

0 commit comments

Comments
 (0)