summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/phpdbg_prompt.c
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2017-01-02 09:44:02 +0000
committerJoe Watkins <krakjoe@php.net>2017-01-02 09:44:02 +0000
commit3e798c4a5f143ca46feab994d5f446c15aef8e98 (patch)
treee1196b654c889dc5de45fda5c99a2d1873a4008f /sapi/phpdbg/phpdbg_prompt.c
parente077735b03fd2339b2d663d29557cfb5ab2d5eff (diff)
parent935b5cb11ed672c42b2a77e10be752702e474e7f (diff)
downloadphp-git-3e798c4a5f143ca46feab994d5f446c15aef8e98.tar.gz
Merge branch 'PHP-7.0' of git.php.net:/php-src into PHP-7.0
* 'PHP-7.0' of git.php.net:/php-src: (146 commits) Flush stderr on win32 in cli_log_message Fixed bug #73154 FIx bug #70213 Fix dom class can't be inherited by the internal class Another try at making concat_003 more reliable Fix flaky openssl_pkey_new test Make Opcache tests using the cli server more reliable Revert "Fix #73530: Unsetting result set may reset other result set" define php_ap_map_http_request_error function for older httpd only add old versions of httpd support Disable AppVeyor fast_finish Makes the sapi web server and curl tests more reliable Fixes the curl tests to be more reliable in Travis CI Interpretation of curl_setopt values for boolean parameters Fixes #65689. PDO_Firebrid / exec() does not free allocated statement. Fix alpn_ctx leaking in openssl Fixed bug #73373 (deflate_add does not verify that output was not truncated) Fix IS_UNDEF comparisons in opcache Fixed bug #73704 (phpdbg shows the wrong line in files with shebang) Increase timing quota for small string concat test ...
Diffstat (limited to 'sapi/phpdbg/phpdbg_prompt.c')
-rw-r--r--sapi/phpdbg/phpdbg_prompt.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index c126ce2029..450e57d02e 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -349,7 +349,9 @@ void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_
void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) /* {{{ */
{
- if (!init_file && use_default) {
+ if (init_file) {
+ phpdbg_try_file_init(init_file, init_file_len, 1);
+ } else if (use_default) {
char *scan_dir = getenv("PHP_INI_SCAN_DIR");
char *sys_ini;
int i;
@@ -382,8 +384,6 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) /
}
phpdbg_try_file_init(PHPDBG_STRL(PHPDBG_INIT_FILENAME), 0);
- } else {
- phpdbg_try_file_init(init_file, init_file_len, 1);
}
}
/* }}} */
@@ -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);