mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
fix bug #76801: phpdbg too many open files error
This commit is contained in:
parent
2e9dccef78
commit
b8b880932e
6 changed files with 53 additions and 34 deletions
3
NEWS
3
NEWS
|
@ -2,6 +2,9 @@ PHP NEWS
|
||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
?? ??? 2019, PHP 7.2.18
|
?? ??? 2019, PHP 7.2.18
|
||||||
|
|
||||||
|
- phpdbg:
|
||||||
|
. Fixed bug #76801 (too many open files). (alekitto)
|
||||||
|
|
||||||
- Reflection:
|
- Reflection:
|
||||||
. Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
|
. Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
|
||||||
|
|
||||||
|
|
|
@ -234,33 +234,33 @@ void phpdbg_list_function_byname(const char *str, size_t len) /* {{{ */
|
||||||
/* Note: do not free the original file handler, let original compile_file() or caller do that. Caller may rely on its value to check success */
|
/* Note: do not free the original file handler, let original compile_file() or caller do that. Caller may rely on its value to check success */
|
||||||
zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
|
zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
|
||||||
phpdbg_file_source data, *dataptr;
|
phpdbg_file_source data, *dataptr;
|
||||||
zend_file_handle fake;
|
|
||||||
zend_op_array *ret;
|
zend_op_array *ret;
|
||||||
char *filename;
|
|
||||||
uint32_t line;
|
uint32_t line;
|
||||||
char *bufptr, *endptr;
|
char *bufptr, *endptr;
|
||||||
|
int size;
|
||||||
|
|
||||||
if (zend_stream_fixup(file, &bufptr, &data.len) == FAILURE) {
|
ret = PHPDBG_G(compile_file)(file, type);
|
||||||
return PHPDBG_G(compile_file)(file, type);
|
if (ret == NULL) {
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename);
|
if (file->type == ZEND_HANDLE_MAPPED) {
|
||||||
|
data.len = file->handle.stream.mmap.len;
|
||||||
|
data.buf = emalloc(data.len + 1);
|
||||||
|
memcpy(data.buf, file->handle.stream.mmap.buf, data.len);
|
||||||
|
} else {
|
||||||
|
if (file->type == ZEND_HANDLE_FILENAME) {
|
||||||
|
zend_stream_open(file->filename, file);
|
||||||
|
}
|
||||||
|
|
||||||
data.buf = emalloc(data.len + ZEND_MMAP_AHEAD + 1);
|
size = file->handle.stream.fsizer(file->handle.stream.handle);
|
||||||
if (data.len > 0) {
|
data.buf = emalloc(size + 1);
|
||||||
memcpy(data.buf, bufptr, data.len);
|
data.len = file->handle.stream.reader(file->handle.stream.handle, data.buf, size);
|
||||||
}
|
}
|
||||||
memset(data.buf + data.len, 0, ZEND_MMAP_AHEAD + 1);
|
|
||||||
|
memset(data.buf + data.len, 0, 1);
|
||||||
|
|
||||||
data.line[0] = 0;
|
data.line[0] = 0;
|
||||||
|
|
||||||
memset(&fake, 0, sizeof(fake));
|
|
||||||
fake.type = ZEND_HANDLE_MAPPED;
|
|
||||||
fake.handle.stream.mmap.buf = data.buf;
|
|
||||||
fake.handle.stream.mmap.len = data.len;
|
|
||||||
fake.free_filename = 0;
|
|
||||||
fake.filename = filename;
|
|
||||||
fake.opened_path = file->opened_path;
|
|
||||||
|
|
||||||
*(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint32_t) * data.len)) = data;
|
*(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint32_t) * data.len)) = data;
|
||||||
|
|
||||||
for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) {
|
for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) {
|
||||||
|
@ -268,28 +268,14 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
|
||||||
dataptr->line[++line] = (uint32_t)(bufptr - data.buf) + 1;
|
dataptr->line[++line] = (uint32_t)(bufptr - data.buf) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dataptr->lines = ++line;
|
dataptr->lines = ++line;
|
||||||
|
dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint32_t) * line);
|
||||||
dataptr->line[line] = endptr - data.buf;
|
dataptr->line[line] = endptr - data.buf;
|
||||||
|
|
||||||
ret = PHPDBG_G(compile_file)(&fake, type);
|
|
||||||
|
|
||||||
if (ret == NULL) {
|
|
||||||
efree(data.buf);
|
|
||||||
efree(dataptr);
|
|
||||||
|
|
||||||
fake.opened_path = NULL;
|
|
||||||
zend_file_handle_dtor(&fake);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint32_t) * line);
|
|
||||||
zend_hash_add_ptr(&PHPDBG_G(file_sources), ret->filename, dataptr);
|
zend_hash_add_ptr(&PHPDBG_G(file_sources), ret->filename, dataptr);
|
||||||
phpdbg_resolve_pending_file_break(ZSTR_VAL(ret->filename));
|
phpdbg_resolve_pending_file_break(ZSTR_VAL(ret->filename));
|
||||||
|
|
||||||
fake.opened_path = NULL;
|
|
||||||
zend_file_handle_dtor(&fake);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
sapi/phpdbg/tests/bug76801.phpt
Normal file
15
sapi/phpdbg/tests/bug76801.phpt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
--TEST--
|
||||||
|
include()ing files should not raise "too many open files" error
|
||||||
|
--PHPDBG--
|
||||||
|
r
|
||||||
|
q
|
||||||
|
--EXPECTF--
|
||||||
|
[Successful compilation of %s]
|
||||||
|
prompt> [Script ended normally]
|
||||||
|
prompt>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
for ($i = 0; $i < 25000; ++$i) {
|
||||||
|
include __DIR__.'/empty.inc';
|
||||||
|
}
|
0
sapi/phpdbg/tests/empty.inc
Normal file
0
sapi/phpdbg/tests/empty.inc
Normal file
15
sapi/phpdbg/tests/include_once_002.phpt
Normal file
15
sapi/phpdbg/tests/include_once_002.phpt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
--TEST--
|
||||||
|
include_once must include only once #2
|
||||||
|
--PHPDBG--
|
||||||
|
r
|
||||||
|
q
|
||||||
|
--EXPECTF--
|
||||||
|
[Successful compilation of %s]
|
||||||
|
prompt> 1
|
||||||
|
[Script ended normally]
|
||||||
|
prompt>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
include __DIR__.'/include.inc';
|
||||||
|
include_once __DIR__.'/include.inc';
|
Loading…
Add table
Add a link
Reference in a new issue