del php-src: NEWS ext/standard/tests/file/bug52820.phpt sapi/phpdbg/config.m4 sapi/phpdbg/config.w32 sapi/phpdbg/phpdbg.c sapi/phpdbg/phpdbg_bp.c
sapi/phpdbg/phpdbg_bp.h sap i/phpdbg/phpdbg_io.c sapi/phpdbg/phpdbg_out.c sapi/ phpdbg/phpdbg_prompt.c sapi/phpdbg/phpdbg_prompt.h
sapi/phpdbg/phpdbg_rinit_hook.c sapi/phpdbg/phpdbg_wa it.c sapi/phpdbg/phpdbg_webdata_transfer.c
| From: | JulienPauli | Date: | Wed, 29 Oct 2014 14:34:04 +0000 |
| Subject: | del php-src: NEWS ext/standard/tests/file/bug52820.phpt sapi/phpdbg/config.m4 sapi/phpdbg/config.w32 sapi/phpdbg/phpdbg.c sapi/phpdbg/phpdbg_bp.c sapi/phpdbg/phpdbg_bp.h sap i/phpdbg/phpdbg_io.c sapi/phpdbg/phpdbg_out.c sapi/ phpdbg/phpdbg_prompt.c sapi/phpdbg/phpdbg_prompt.h sapi/phpdbg/phpdbg_rinit_hook.c sapi/phpdbg/phpdbg_wa it.c sapi/phpdbg/phpdbg_webdata_transfer.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82865@lists.php.net to get a copy of this message | ||
Branch: PHP-5.6.3
Deleted commits count: 1
User: JulienPauli <jpauli@php.net> Wed, 29 Oct 2014 14:34:04 +0000
Changed paths:
M NEWS
M ext/standard/tests/file/bug52820.phpt
M sapi/phpdbg/config.m4
M sapi/phpdbg/config.w32
M sapi/phpdbg/phpdbg.c
M sapi/phpdbg/phpdbg_bp.c
M sapi/phpdbg/phpdbg_bp.h
M sapi/phpdbg/phpdbg_io.c
M sapi/phpdbg/phpdbg_out.c
M sapi/phpdbg/phpdbg_prompt.c
M sapi/phpdbg/phpdbg_prompt.h
M sapi/phpdbg/phpdbg_rinit_hook.c
M sapi/phpdbg/phpdbg_wait.c
M sapi/phpdbg/phpdbg_webdata_transfer.c
diff --git b/NEWS a/NEWS index f8f4721..478fa1d 100644 --- b/NEWS +++ a/NEWS @@ -1,6 +1,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -30 Oct 2014, PHP 5.6.3RC1 +?? ??? 2014, PHP 5.6.4 + + + +?? ??? 2014, PHP 5.6.3 - Core: . Implemented 64-bit format codes for pack() and unpack(). (Leigh) diff --git b/ext/standard/tests/file/bug52820.phpt a/ext/standard/tests/file/bug52820.phpt index 3a9f9c3..a00ebf5 100644 --- b/ext/standard/tests/file/bug52820.phpt +++ a/ext/standard/tests/file/bug52820.phpt @@ -1,71 +1,63 @@ ---TEST-- -Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream) ---SKIPIF-- -<?php -if (!function_exists('leak_variable')) - die("skip only for debug builds"); -/* unfortunately no standard function does a cast to FILE*, so we need - * curl to test this */ -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -$handle=curl_init('http://127.0.0.1:37349/'); -curl_setopt($handle, CURLOPT_VERBOSE, true); -curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); -if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+"))) - die("skip fopencookie not supported on this platform"); ---FILE-- -<?php -function do_stuff($url) { - $handle=curl_init('http://127.0.0.1:37349/'); - curl_setopt($handle, CURLOPT_VERBOSE, true); - curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); - curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+")); - curl_exec($handle); - echo "About to rewind!\n"; - rewind($o); - echo stream_get_contents($o); - return $o; -} - -echo "temp stream (close after):\n"; -fclose(do_stuff("php://temp")); - -echo "\nmemory stream (close after):\n"; -fclose(do_stuff("php://memory")); - -echo "\ntemp stream (leak):\n"; -leak_variable(do_stuff("php://temp"), true); - -echo "\nmemory stream (leak):\n"; -leak_variable(do_stuff("php://memory"), true); - -echo "\nDone.\n"; ---EXPECTF-- -temp stream (close after): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -memory stream (close after): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -temp stream (leak): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -memory stream (leak): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -Done. +--TEST-- +Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream) +--SKIPIF-- +<?php +if (!function_exists('leak_variable')) + die("skip only for debug builds"); +/* unfortunately no standard function does a cast to FILE*, so we need + * curl to test this */ +if (!extension_loaded("curl")) exit("skip curl extension not loaded"); +$handle=curl_init('http://127.0.0.1:37349/'); +curl_setopt($handle, CURLOPT_VERBOSE, true); +curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); +if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+"))) + die("skip fopencookie not supported on this platform"); +--FILE-- +<?php +function do_stuff($url) { + $handle=curl_init('http://127.0.0.1:37349/'); + curl_setopt($handle, CURLOPT_VERBOSE, true); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+")); + curl_exec($handle); + echo "About to rewind!\n"; + rewind($o); + echo stream_get_contents($o); + return $o; +} + +echo "temp stream (close after):\n"; +fclose(do_stuff("php://temp")); + +echo "\nmemory stream (close after):\n"; +fclose(do_stuff("php://memory")); + +echo "\ntemp stream (leak):\n"; +leak_variable(do_stuff("php://temp"), true); + +echo "\nmemory stream (leak):\n"; +leak_variable(do_stuff("php://memory"), true); + +echo "\nDone.\n"; +--EXPECTF-- +temp stream (close after): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +memory stream (close after): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +temp stream (leak): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +memory stream (leak): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +Done. diff --git b/sapi/phpdbg/config.m4 a/sapi/phpdbg/config.m4 index 528abb5..87d38ea 100644 --- b/sapi/phpdbg/config.m4 +++ a/sapi/phpdbg/config.m4 @@ -22,14 +22,10 @@ if test "$BUILD_PHPDBG" == "" && test "$PHP_PHPDBG" != "no"; then fi if test "$PHP_PHPDBG_WEBHELPER" != "no"; then - if ! test -d ext/phpdbg_webhelper; then - ln -s ../sapi/phpdbg ext/phpdbg_webhelper - fi - if test "$PHP_JSON" != "no"; then - PHP_NEW_EXTENSION(phpdbg_webhelper, phpdbg_rinit_hook.c phpdbg_webdata_transfer.c, $ext_shared) - else - AC_MSG_ERROR(Webhelper extension of phpdbg needs json enabled) + if ! test -d $abs_srcdir/ext/phpdbg_webhelper; then + ln -s ../sapi/phpdbg $abs_srcdir/ext/phpdbg_webhelper fi + PHP_NEW_EXTENSION(phpdbg_webhelper, phpdbg_rinit_hook.c phpdbg_webdata_transfer.c, $ext_shared) fi PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE" diff --git b/sapi/phpdbg/config.w32 a/sapi/phpdbg/config.w32 index 6f0bd8f..651c7e6 100644 --- b/sapi/phpdbg/config.w32 +++ a/sapi/phpdbg/config.w32 @@ -1,5 +1,6 @@ ARG_ENABLE('phpdbg', 'Build phpdbg', 'no'); ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no'); +ARG_ENABLE('phpdbgwebhelper', 'Build phpdbg webhelper', 'yes'); PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' + 'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' + @@ -14,6 +15,10 @@ if (PHP_PHPDBG == "yes") { ADD_FLAG("LIBS_PHPDBG", "ws2_32.lib user32.lib"); ADD_FLAG("CFLAGS_PHPDBG", "/D YY_NO_UNISTD_H"); ADD_FLAG("LDFLAGS_PHPDBG", "/stack:8388608"); + + if (PHP_PHPDBGWEBHELPER == "yes") { + EXTENSION('phpdbg-webhelper', 'phpdbg_rinit_hook.c phpdbg_webdata_compress.c'); + } } if (PHP_PHPDBGS == "yes") { diff --git b/sapi/phpdbg/phpdbg.c a/sapi/phpdbg/phpdbg.c index 9c56b1d..5ebc203 100644 --- b/sapi/phpdbg/phpdbg.c +++ a/sapi/phpdbg/phpdbg.c @@ -1039,13 +1039,7 @@ int main(int argc, char **argv) /* {{{ */ zend_bool remote = 0; int step = 0; zend_phpdbg_globals *settings = NULL; - -#ifdef _WIN32 - char *bp_tmp_file = NULL; -#else - char bp_tmp_file[] = "/tmp/phpdbg.XXXXXX"; -#endif - + char *bp_tmp = NULL; char *address; int listen = -1; int server = -1; @@ -1081,29 +1075,6 @@ int main(int argc, char **argv) /* {{{ */ #endif phpdbg_main: - if (!cleaning) { - -#ifdef _WIN32 - bp_tmp_file = malloc(L_tmpnam); - - if (bp_tmp_file) { - if (!tmpnam(bp_tmp_file)) { - free(bp_tmp_file); - bp_tmp_file = NULL; - } - } - - if (!bp_tmp_file) { - phpdbg_error("tmpfile", "", "Unable to create temporary file"); - return 1; - } -#else - if (!mkstemp(bp_tmp_file)) { - memset(bp_tmp_file, 0, sizeof(bp_tmp_file)); - } -#endif - - } ini_entries = NULL; ini_entries_len = 0; ini_ignore = 0; @@ -1466,7 +1437,7 @@ phpdbg_main: if (exec) { /* set execution context */ PHPDBG_G(exec) = phpdbg_resolve_path(exec TSRMLS_CC); - PHPDBG_G(exec_len) = strlen(exec); + PHPDBG_G(exec_len) = PHPDBG_G(exec) ? strlen(PHPDBG_G(exec)) : 0; free(exec); exec = NULL; @@ -1502,9 +1473,13 @@ phpdbg_main: PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; zend_try { phpdbg_init(init_file, init_file_len, init_file_default TSRMLS_CC); - PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; - phpdbg_try_file_init(bp_tmp_file, strlen(bp_tmp_file), 0 TSRMLS_CC); - PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + if (bp_tmp) { + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; + phpdbg_string_init(bp_tmp TSRMLS_CC); + free(bp_tmp); + bp_tmp = NULL; + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + } } zend_end_try(); PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; @@ -1527,29 +1502,32 @@ phpdbg_main: PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; } - if (phpdbg_startup_run) { - zend_try { - PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC); - } zend_end_try(); - if (phpdbg_startup_run > 1) { - /* if -r is on the command line more than once just quit */ - goto phpdbg_out; - } - phpdbg_startup_run = 0; - } - phpdbg_interact: /* phpdbg main() */ do { zend_try { + if (phpdbg_startup_run) { + zend_bool quit_immediately = phpdbg_startup_run > 1; + phpdbg_startup_run = 0; + PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC); + if (quit_immediately) { + /* if -r is on the command line more than once just quit */ + EG(bailout) = __orig_bailout; /* reset zend_try */ + break; + } + } + phpdbg_interactive(1 TSRMLS_CC); } zend_catch { if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) { - FILE *bp_tmp_fp = fopen(bp_tmp_file, "w"); + char *bp_tmp_str; PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; - phpdbg_export_breakpoints(bp_tmp_fp TSRMLS_CC); + phpdbg_export_breakpoints_to_string(&bp_tmp_str TSRMLS_CC); PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; - fclose(bp_tmp_fp); + if (bp_tmp_str) { + bp_tmp = strdup(bp_tmp_str); + efree(bp_tmp_str); + } cleaning = 1; } else { cleaning = 0; @@ -1689,11 +1667,5 @@ phpdbg_out: free(PHPDBG_G(sapi_name_ptr)); } -#ifdef _WIN32 - free(bp_tmp_file); -#else - unlink(bp_tmp_file); -#endif - return 0; } /* }}} */ diff --git b/sapi/phpdbg/phpdbg_bp.c a/sapi/phpdbg/phpdbg_bp.c index cf28a33..33824d4 100644 --- b/sapi/phpdbg/phpdbg_bp.c +++ a/sapi/phpdbg/phpdbg_bp.c @@ -111,10 +111,19 @@ PHPDBG_API void phpdbg_reset_breakpoints(TSRMLS_D) /* {{{ */ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ { + char *string; + phpdbg_export_breakpoints_to_string(&string TSRMLS_CC); + fputs(string, handle); +} + +PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str TSRMLS_DC) /* {{{ */ +{ HashPosition position[2]; HashTable **table = NULL; zend_ulong id = 0L; + *str = ""; + if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) { phpdbg_notice("exportbreakpoint", "count=\"%d\"", "Exporting %d breakpoints", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])); /* this only looks like magic, it isn't */ @@ -126,55 +135,57 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], NULL, NULL, &id, 0, &position[0]); for (zend_hash_internal_pointer_reset_ex((*table), &position[1]); - zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex((*table), &position[1])) { + zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS; + zend_hash_move_forward_ex((*table), &position[1])) { if (brake->id == id) { + char *new_str = NULL; + switch (brake->type) { case PHPDBG_BREAK_FILE: { - fprintf(handle, - "break %s:%lu\n", + phpdbg_asprintf(&new_str, + "%sbreak %s:%lu\n", *str, ((phpdbg_breakfile_t*)brake)->filename, ((phpdbg_breakfile_t*)brake)->line); } break; case PHPDBG_BREAK_SYM: { - fprintf(handle, - "break %s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s\n", *str, ((phpdbg_breaksymbol_t*)brake)->symbol); } break; case PHPDBG_BREAK_METHOD: { - fprintf(handle, - "break %s::%s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s::%s\n", *str, ((phpdbg_breakmethod_t*)brake)->class_name, ((phpdbg_breakmethod_t*)brake)->func_name); } break; case PHPDBG_BREAK_METHOD_OPLINE: { - fprintf(handle, - "break %s::%s#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s::%s#%ld\n", *str, ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_FUNCTION_OPLINE: { - fprintf(handle, - "break %s#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s#%ld\n", *str, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_FILE_OPLINE: { - fprintf(handle, - "break %s:#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s:#%ld\n", *str, ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_OPCODE: { - fprintf(handle, - "break %s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s\n", *str, ((phpdbg_breakop_t*)brake)->name); } break; @@ -184,20 +195,20 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ if (conditional->paramed) { switch (conditional->param.type) { case STR_PARAM: - fprintf(handle, - "break at %s if %s\n", conditional->param.str, conditional->code); + phpdbg_asprintf(&new_str, + "%sbreak at %s if %s\n", *str, conditional->param.str, conditional->code); break; case METHOD_PARAM: - fprintf(handle, - "break at %s::%s if %s\n", + phpdbg_asprintf(&new_str, + "%sbreak at %s::%s if %s\n", *str, conditional->param.method.class, conditional->param.method.name, conditional->code); break; case FILE_PARAM: - fprintf(handle, - "break at %s:%lu if %s\n", + phpdbg_asprintf(&new_str, + "%sbreak at %s:%lu if %s\n", *str, conditional->param.file.name, conditional->param.file.line, conditional->code); break; @@ -205,15 +216,23 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ default: { /* do nothing */ } break; } } else { - fprintf( - handle, "break if %s\n", conditional->code); + phpdbg_asprintf(&new_str, "%sbreak if %s\n", str, conditional->code); } } break; } + + if ((*str)[0]) { + efree(*str); + } + *str = new_str; } } } } + + if (!(*str)[0]) { + *str = NULL; + } } /* }}} */ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */ @@ -232,6 +251,8 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML } path_len = strlen(path); + phpdbg_debug("file path: %s, resolved path: %s, was compiled: %d\n", original_path, path, zend_hash_exists(&PHPDBG_G(file_sources), path, path_len)); + if (!zend_hash_exists(&PHPDBG_G(file_sources), path, path_len)) { if (php_stream_stat_path(path, &ssb) == FAILURE) { if (original_path[0] == '/') { @@ -246,6 +267,8 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML } else if (!(ssb.sb.st_mode & (S_IFREG|S_IFLNK))) { phpdbg_error("breakpoint", "type=\"notregular\" add=\"fail\" file=\"%s\"", "Cannot set breakpoint in %s, it is not a regular file", path); return; + } else { + phpdbg_debug("File exists, but not compiled\n"); } } @@ -273,9 +296,13 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(file_sources), &position); zend_hash_get_current_key_ex(&PHPDBG_G(file_sources), &file, &filelen, NULL, 0, &position) == HASH_KEY_IS_STRING; zend_hash_move_forward_ex(&PHPDBG_G(file_sources), &position)) { - if (!(pending = ((broken = phpdbg_resolve_pending_file_break_ex(file, filelen, path, path_len, broken TSRMLS_CC)) == NULL))) { + HashTable *fileht; + + phpdbg_debug("Compare against loaded %s\n", file); + + if (!(pending = ((fileht = phpdbg_resolve_pending_file_break_ex(file, filelen, path, path_len, broken TSRMLS_CC)) == NULL))) { phpdbg_breakfile_t *brake; - zend_hash_index_find(broken, line_num, (void **) &brake); + zend_hash_index_find(fileht, line_num, (void **) &brake); new_break = *brake; break; } @@ -298,18 +325,19 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, const char *cur, uint curlen, HashTable *fileht TSRMLS_DC) /* {{{ */ { - if (curlen < filelen && file[filelen - curlen - 1] == '/' && !memcmp(file + filelen - curlen, cur, curlen)) { + phpdbg_debug("file: %s, filelen: %u, cur: %s, curlen %u, pos: %c, memcmp: %d\n", file, filelen, cur, curlen, filelen > curlen ? file[filelen - curlen - 1] : '?', filelen > curlen ? memcmp(file + filelen - curlen, cur, curlen) : 0); + + if (((curlen < filelen && file[filelen - curlen - 1] == '/') || filelen == curlen) && !memcmp(file + filelen - curlen, cur, curlen)) { phpdbg_breakfile_t *brake, new_brake; HashTable *master = NULL; HashPosition position; - dtor_func_t dtor; PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, (void **) &master) == FAILURE) { - dtor = PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING].pDestructor; - PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING].pDestructor = NULL; - zend_hash_add(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, fileht, sizeof(HashTable), (void **) &fileht); + HashTable new_ht; + zend_hash_init(&new_ht, 8, NULL, phpdbg_file_breaks_dtor, 0); + zend_hash_add(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, &new_ht, sizeof(HashTable), (void **) &master); } for (zend_hash_internal_pointer_reset_ex(fileht, &position); @@ -322,24 +350,18 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin if (master) { zend_hash_index_update(master, brake->line, (void **) &new_brake, sizeof(phpdbg_breakfile_t), NULL); PHPDBG_BREAK_MAPPING(brake->id, master); - } else { - efree((char *) brake->filename); - *brake = new_brake; - PHPDBG_BREAK_MAPPING(brake->id, fileht); } } zend_hash_del(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur, curlen); - if (!master) { - PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING].pDestructor = dtor; - } - if (!zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING])) { PHPDBG_G(flags) &= ~PHPDBG_HAS_PENDING_FILE_BP; } - return fileht; + phpdbg_debug("compiled file: %s, cur bp file: %s\n", file, cur); + + return master; } return NULL; @@ -351,6 +373,8 @@ PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file TSRMLS_DC) /* HashTable *fileht; uint filelen = strlen(file); + phpdbg_debug("was compiled: %s\n", file); + zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], &position); while (zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], (void**) &fileht, &position) == SUCCESS) { const char *cur; @@ -359,6 +383,8 @@ PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file TSRMLS_DC) /* zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], (char **) &cur, &curlen, NULL, 0, &position); zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], &position); + phpdbg_debug("check bp: %s\n", cur); + phpdbg_resolve_pending_file_break_ex(file, filelen, cur, curlen, fileht TSRMLS_CC); } } @@ -877,10 +903,21 @@ static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_ { HashTable *breaks; phpdbg_breakbase_t *brake; - size_t name_len = strlen(op_array->filename); + size_t path_len; + char realpath[MAXPATHLEN]; + const char *path = op_array->filename; + + if (VCWD_REALPATH(path, realpath)) { + path = realpath; + } + + path_len = strlen(path); + +#if 0 + phpdbg_debug("Op at: %.*s %d\n", path_len, path, (*EG(opline_ptr))->lineno); +#endif - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], op_array->filename, - name_len, (void**)&breaks) == FAILURE) { + if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], path, path_len, (void**)&breaks) == FAILURE) { return NULL; } diff --git b/sapi/phpdbg/phpdbg_bp.h a/sapi/phpdbg/phpdbg_bp.h index eca5953..63a9961 100644 --- b/sapi/phpdbg/phpdbg_bp.h +++ a/sapi/phpdbg/phpdbg_bp.h @@ -157,6 +157,7 @@ PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id TSRMLS_DC); PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable ***table, HashPosition *position TSRMLS_DC); /* }}} */ /* {{{ Breakpoint Exportation API */ -PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC); /* }}} */ +PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC); +PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str TSRMLS_DC); /* }}} */ #endif /* PHPDBG_BP_H */ diff --git b/sapi/phpdbg/phpdbg_io.c a/sapi/phpdbg/phpdbg_io.c index 6908a68..a2a5c59 100644 --- b/sapi/phpdbg/phpdbg_io.c +++ a/sapi/phpdbg/phpdbg_io.c @@ -187,10 +187,6 @@ PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_DC PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len TSRMLS_DC) { - if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { - return 0; - } - if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { return phpdbg_send_bytes(sock, ptr, len); } diff --git b/sapi/phpdbg/phpdbg_out.c a/sapi/phpdbg/phpdbg_out.c index 365708c..7e1dc7b 100644 --- b/sapi/phpdbg/phpdbg_out.c +++ a/sapi/phpdbg/phpdbg_out.c @@ -1168,6 +1168,10 @@ PHPDBG_API int phpdbg_output_err_buf(const char *tag, const char *xmlfmt, const va_list args; int errbuf_active = PHPDBG_G(err_buf).active; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + PHPDBG_G(err_buf).active = 0; #ifdef ZTS @@ -1188,6 +1192,10 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, int fd, const char *tag, const c va_list args; int len; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + va_start(args, strfmt); len = phpdbg_vprint(type TSRMLS_CC, fd, tag, xmlfmt, strfmt, args); va_end(args); @@ -1198,6 +1206,10 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, int fd, const char *tag, const c PHPDBG_API int phpdbg_xml_internal(int fd TSRMLS_DC, const char *fmt, ...) { int len = 0; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { va_list args; char *buffer; @@ -1243,6 +1255,10 @@ PHPDBG_API int phpdbg_out_internal(int fd TSRMLS_DC, const char *fmt, ...) { int buflen; int len = 0; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + va_start(args, fmt); buflen = phpdbg_xml_vasprintf(&buffer, fmt, 0, args TSRMLS_CC); va_end(args); diff --git b/sapi/phpdbg/phpdbg_prompt.c a/sapi/phpdbg/phpdbg_prompt.c index 73ecbcb..c1fcb59 100644 --- b/sapi/phpdbg/phpdbg_prompt.c +++ a/sapi/phpdbg/phpdbg_prompt.c @@ -208,98 +208,128 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ * return FAILURE; } /* }}} */ -void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ -{ - struct stat sb; +struct phpdbg_init_state { + int line; + zend_bool in_code; + char *code; + size_t code_len; + const char *init_file; +}; - if (init_file && VCWD_STAT(init_file, &sb) != -1) { - FILE *fp = fopen(init_file, "r"); - if (fp) { - int line = 1; +static void phpdbg_line_init(char *cmd, struct phpdbg_init_state *state TSRMLS_DC) { + size_t cmd_len = strlen(cmd); - char cmd[PHPDBG_MAX_CMD]; - size_t cmd_len = 0L; - char *code = NULL; - size_t code_len = 0L; - zend_bool in_code = 0; + state->line++; - while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { - cmd_len = strlen(cmd)-1; - - while (cmd_len > 0L && isspace(cmd[cmd_len-1])) - cmd_len--; - - cmd[cmd_len] = '\0'; - - if (*cmd && cmd_len > 0L && cmd[0] != '#') { - if (cmd_len == 2) { - if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { - in_code = 1; - goto next_line; - } else { - if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { - in_code = 0; - code[code_len] = '\0'; - { - zend_eval_stringl(code, code_len, NULL, "phpdbginit code" TSRMLS_CC); - } - free(code); - code = NULL; - goto next_line; - } - } - } + while (cmd_len > 0L && isspace(cmd[cmd_len-1])) { + cmd_len--; + } - if (in_code) { - if (code == NULL) { - code = malloc(cmd_len + 1); - } else code = realloc(code, code_len + cmd_len + 1); + cmd[cmd_len] = '\0'; - if (code) { - memcpy( - &code[code_len], cmd, cmd_len); - code_len += cmd_len; - } - goto next_line; - } + if (*cmd && cmd_len > 0L && cmd[0] != '#') { + if (cmd_len == 2) { + if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { + state->in_code = 1; + return; + } else { + if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { + state->in_code = 0; + state->code[state->code_len] = '\0'; + zend_eval_stringl(state->code, state->code_len, NULL, "phpdbginit code" TSRMLS_CC); + free(state->code); + state->code = NULL; + return; + } + } + } - zend_try { - char *input = phpdbg_read_input(cmd TSRMLS_CC); - phpdbg_param_t stack; + if (state->in_code) { + if (state->code == NULL) { + state->code = malloc(cmd_len + 1); + } else { + state->code = realloc(state->code, state->code_len + cmd_len + 1); + } - phpdbg_init_param(&stack, STACK_PARAM); + if (state->code) { + memcpy(&state->code[state->code_len], cmd, cmd_len); + state->code_len += cmd_len; + } - phpdbg_activate_err_buf(1 TSRMLS_CC); + return; + } - if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { - switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */ TSRMLS_CC)) { - case FAILURE: - phpdbg_activate_err_buf(0 TSRMLS_CC); - if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { - phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!" TSRMLS_CC, init_file, line, input); - } - break; - } - } + zend_try { + char *input = phpdbg_read_input(cmd TSRMLS_CC); + phpdbg_param_t stack; + + phpdbg_init_param(&stack, STACK_PARAM); + + phpdbg_activate_err_buf(1 TSRMLS_CC); + if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { + switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */ TSRMLS_CC)) { + case FAILURE: phpdbg_activate_err_buf(0 TSRMLS_CC); - phpdbg_free_err_buf(TSRMLS_C); - - phpdbg_stack_free(&stack); - phpdbg_destroy_input(&input TSRMLS_CC); - } zend_catch { - PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); - if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { - zend_bailout(); + if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { + if (state->init_file) { + phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!" TSRMLS_CC, state->init_file, state->line, input); + } else { + phpdbg_output_err_buf("initfailure", "%b line=\"%d\" input=\"%s\"", "Unrecognized command on line %d: %s, %b!" TSRMLS_CC, state->line, input); + } } - } zend_end_try(); + break; } -next_line: - line++; } - if (code) { - free(code); + phpdbg_activate_err_buf(0 TSRMLS_CC); + phpdbg_free_err_buf(TSRMLS_C); + + phpdbg_stack_free(&stack); + phpdbg_destroy_input(&input TSRMLS_CC); + } zend_catch { + PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); + if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + zend_bailout(); + } + } zend_end_try(); + } + +} + +void phpdbg_string_init(char *buffer TSRMLS_DC) { + struct phpdbg_init_state state = {0}; + char *str = strtok(buffer, "\n"); + + while (str) { + phpdbg_line_init(str, &state TSRMLS_CC); + + str = strtok(NULL, "\n"); + } + + if (state.code) { + free(state.code); + } +} + +void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ +{ + struct stat sb; + + if (init_file && VCWD_STAT(init_file, &sb) != -1) { + FILE *fp = fopen(init_file, "r"); + if (fp) { + char cmd[PHPDBG_MAX_CMD]; + struct phpdbg_init_state state = {0}; + + state.init_file = init_file; + + while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { + phpdbg_line_init(cmd, &state TSRMLS_CC); + } + + if (state.code) { + free(state.code); } fclose(fp); @@ -676,10 +706,10 @@ PHPDBG_COMMAND(run) /* {{{ */ EG(active_op_array) = orig_op_array; EG(opline_ptr) = orig_opline; EG(return_value_ptr_ptr) = orig_retval_ptr; - - phpdbg_clean(1 TSRMLS_CC); } + phpdbg_clean(1 TSRMLS_CC); + PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; } else { phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); @@ -1132,7 +1162,7 @@ PHPDBG_COMMAND(register) /* {{{ */ phpdbg_notice("register", "function=\"%s\"", "Registered %s", lcname); } else { - phpdbg_error("register", "type=\"notfoundc\" function=\"%s\"", "The requested function (%s) could not be found", param->str); + phpdbg_error("register", "type=\"notfound\" function=\"%s\"", "The requested function (%s) could not be found", param->str); } } else { phpdbg_error("register", "type=\"inuse\" function=\"%s\"", "The requested name (%s) is already in use", lcname); diff --git b/sapi/phpdbg/phpdbg_prompt.h a/sapi/phpdbg/phpdbg_prompt.h index 94e24df..f583f2c 100644 --- b/sapi/phpdbg/phpdbg_prompt.h +++ a/sapi/phpdbg/phpdbg_prompt.h @@ -22,6 +22,7 @@ #define PHPDBG_PROMPT_H /* {{{ */ +void phpdbg_string_init(char *buffer TSRMLS_DC); void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC); void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC); int phpdbg_interactive(zend_bool allow_async_unsafe TSRMLS_DC); diff --git b/sapi/phpdbg/phpdbg_rinit_hook.c a/sapi/phpdbg/phpdbg_rinit_hook.c index 049a782..acbdfb6 100644 --- b/sapi/phpdbg/phpdbg_rinit_hook.c +++ a/sapi/phpdbg/phpdbg_rinit_hook.c @@ -99,3 +99,7 @@ zend_module_entry phpdbg_webhelper_module_entry = { PHPDBG_VERSION, STANDARD_MODULE_PROPERTIES }; + +#ifdef COMPILE_DL_PHPDBG_WEBHELPER +ZEND_GET_MODULE(phpdbg_webhelper) +#endif diff --git b/sapi/phpdbg/phpdbg_wait.c a/sapi/phpdbg/phpdbg_wait.c index ea506a2..95024b8 100644 --- b/sapi/phpdbg/phpdbg_wait.c +++ a/sapi/phpdbg/phpdbg_wait.c @@ -18,11 +18,10 @@ #include "phpdbg_wait.h" #include "phpdbg_prompt.h" -#include "ext/json/JSON_parser.h" +#include "ext/standard/php_var.h" #include "ext/standard/basic_functions.h" ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -ZEND_EXTERN_MODULE_GLOBALS(json); static void phpdbg_rebuild_http_globals_array(int type, const char *name TSRMLS_DC) { zval **zvpp; @@ -127,16 +126,18 @@ static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval ***ptr) { } void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { -#ifdef HAVE_JSON zval *free_zv = NULL; - zval zv, **zvpp; + zval zv, *zvp = &zv, **zvpp; HashTable *ht; - php_json_decode(&zv, msg, len, 1, 1000 /* enough */ TSRMLS_CC); + php_unserialize_data_t var_hash; - if (JSON_G(error_code) != PHP_JSON_ERROR_NONE) { - phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed JSON was sent to this socket, arborting"); + PHP_VAR_UNSERIALIZE_INIT(var_hash); + if (!php_var_unserialize(&zvp, (const unsigned char **) &msg, (unsigned char *) msg + len, &var_hash TSRMLS_CC)) { + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed serialized was sent to this socket, arborting"); return; } + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); ht = Z_ARRVAL(zv); @@ -172,6 +173,7 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { free_zv = *zvpp; } +#if PHP_VERSION_ID >= 50600 if (zend_hash_find(ht, "input", sizeof("input"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_STRING) { if (SG(request_info).request_body) { php_stream_close(SG(request_info).request_body); @@ -180,6 +182,7 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { php_stream_truncate_set_size(SG(request_info).request_body, 0); php_stream_write(SG(request_info).request_body, Z_STRVAL_PP(zvpp), Z_STRLEN_PP(zvpp)); } +#endif if (zend_hash_find(ht, "cwd", sizeof("cwd"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_STRING) { if (VCWD_CHDIR(Z_STRVAL_PP(zvpp)) == SUCCESS) { @@ -358,12 +361,10 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { /* Reapply raw input */ /* ??? */ -#endif } PHPDBG_COMMAND(wait) /* {{{ */ { -#ifdef HAVE_JSON struct sockaddr_un local, remote; int rlen, sr, sl; unlink(PHPDBG_G(socket_path)); @@ -415,5 +416,4 @@ PHPDBG_COMMAND(wait) /* {{{ */ phpdbg_notice("wait", "import=\"success\"", "Successfully imported request data, stopped before executing"); return SUCCESS; -#endif } /* }}} */ diff --git b/sapi/phpdbg/phpdbg_webdata_transfer.c a/sapi/phpdbg/phpdbg_webdata_transfer.c index e7438ea..7c169ee 100644 --- b/sapi/phpdbg/phpdbg_webdata_transfer.c +++ a/sapi/phpdbg/phpdbg_webdata_transfer.c @@ -17,11 +17,9 @@ */ #include "phpdbg_webdata_transfer.h" -#include "ext/json/php_json.h" +#include "ext/standard/php_var.h" PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { -#ifdef HAVE_JSON - smart_str buf = {0}; zval array; HashTable *ht; /* I really need to change that to an array of zvals... */ @@ -51,6 +49,7 @@ PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { zend_hash_add(ht, "GLOBALS", sizeof("GLOBALS"), &zvp1, sizeof(zval *), NULL); } +#if PHP_VERSION_ID >= 50600 /* save php://input */ { php_stream *stream; @@ -66,6 +65,7 @@ PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { Z_SET_REFCOUNT(zv2, 2); zend_hash_add(ht, "input", sizeof("input"), &zvp2, sizeof(zval *), NULL); } +#endif /* change sapi name */ { @@ -177,9 +177,17 @@ PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { } /* encode data */ - php_json_encode(&buf, &array, 0 TSRMLS_CC); - *msg = buf.c; - *len = buf.len; + { + php_serialize_data_t var_hash; + smart_str buf = {0}; + zval *arrayptr = &array; + + PHP_VAR_SERIALIZE_INIT(var_hash); + php_var_serialize(&buf, &arrayptr, &var_hash TSRMLS_CC); + PHP_VAR_SERIALIZE_DESTROY(var_hash); + *msg = buf.c; + *len = buf.len; + } + zval_dtor(&array); -#endif }
diff --git b/NEWS a/NEWS index f8f4721..478fa1d 100644 --- b/NEWS +++ a/NEWS @@ -1,6 +1,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -30 Oct 2014, PHP 5.6.3RC1 +?? ??? 2014, PHP 5.6.4 + + + +?? ??? 2014, PHP 5.6.3 - Core: . Implemented 64-bit format codes for pack() and unpack(). (Leigh) diff --git b/ext/standard/tests/file/bug52820.phpt a/ext/standard/tests/file/bug52820.phpt index 3a9f9c3..a00ebf5 100644 --- b/ext/standard/tests/file/bug52820.phpt +++ a/ext/standard/tests/file/bug52820.phpt @@ -1,71 +1,63 @@ ---TEST-- -Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream) ---SKIPIF-- -<?php -if (!function_exists('leak_variable')) - die("skip only for debug builds"); -/* unfortunately no standard function does a cast to FILE*, so we need - * curl to test this */ -if (!extension_loaded("curl")) exit("skip curl extension not loaded"); -$handle=curl_init('http://127.0.0.1:37349/'); -curl_setopt($handle, CURLOPT_VERBOSE, true); -curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); -if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+"))) - die("skip fopencookie not supported on this platform"); ---FILE-- -<?php -function do_stuff($url) { - $handle=curl_init('http://127.0.0.1:37349/'); - curl_setopt($handle, CURLOPT_VERBOSE, true); - curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); - curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+")); - curl_exec($handle); - echo "About to rewind!\n"; - rewind($o); - echo stream_get_contents($o); - return $o; -} - -echo "temp stream (close after):\n"; -fclose(do_stuff("php://temp")); - -echo "\nmemory stream (close after):\n"; -fclose(do_stuff("php://memory")); - -echo "\ntemp stream (leak):\n"; -leak_variable(do_stuff("php://temp"), true); - -echo "\nmemory stream (leak):\n"; -leak_variable(do_stuff("php://memory"), true); - -echo "\nDone.\n"; ---EXPECTF-- -temp stream (close after): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -memory stream (close after): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -temp stream (leak): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -memory stream (leak): -About to rewind! -* About to connect() to 127.0.0.1 port 37349%r.*%r -* Trying 127.0.0.1...%A* Connection refused -* couldn't connect to host%S -* Closing connection #0 - -Done. +--TEST-- +Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream) +--SKIPIF-- +<?php +if (!function_exists('leak_variable')) + die("skip only for debug builds"); +/* unfortunately no standard function does a cast to FILE*, so we need + * curl to test this */ +if (!extension_loaded("curl")) exit("skip curl extension not loaded"); +$handle=curl_init('http://127.0.0.1:37349/'); +curl_setopt($handle, CURLOPT_VERBOSE, true); +curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); +if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+"))) + die("skip fopencookie not supported on this platform"); +--FILE-- +<?php +function do_stuff($url) { + $handle=curl_init('http://127.0.0.1:37349/'); + curl_setopt($handle, CURLOPT_VERBOSE, true); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+")); + curl_exec($handle); + echo "About to rewind!\n"; + rewind($o); + echo stream_get_contents($o); + return $o; +} + +echo "temp stream (close after):\n"; +fclose(do_stuff("php://temp")); + +echo "\nmemory stream (close after):\n"; +fclose(do_stuff("php://memory")); + +echo "\ntemp stream (leak):\n"; +leak_variable(do_stuff("php://temp"), true); + +echo "\nmemory stream (leak):\n"; +leak_variable(do_stuff("php://memory"), true); + +echo "\nDone.\n"; +--EXPECTF-- +temp stream (close after): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +memory stream (close after): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +temp stream (leak): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +memory stream (leak): +About to rewind! +* %ATrying 127.0.0.1...%AConnection refused%A +* Closing connection%A%d + +Done. diff --git b/sapi/phpdbg/config.m4 a/sapi/phpdbg/config.m4 index 528abb5..87d38ea 100644 --- b/sapi/phpdbg/config.m4 +++ a/sapi/phpdbg/config.m4 @@ -22,14 +22,10 @@ if test "$BUILD_PHPDBG" == "" && test "$PHP_PHPDBG" != "no"; then fi if test "$PHP_PHPDBG_WEBHELPER" != "no"; then - if ! test -d ext/phpdbg_webhelper; then - ln -s ../sapi/phpdbg ext/phpdbg_webhelper - fi - if test "$PHP_JSON" != "no"; then - PHP_NEW_EXTENSION(phpdbg_webhelper, phpdbg_rinit_hook.c phpdbg_webdata_transfer.c, $ext_shared) - else - AC_MSG_ERROR(Webhelper extension of phpdbg needs json enabled) + if ! test -d $abs_srcdir/ext/phpdbg_webhelper; then + ln -s ../sapi/phpdbg $abs_srcdir/ext/phpdbg_webhelper fi + PHP_NEW_EXTENSION(phpdbg_webhelper, phpdbg_rinit_hook.c phpdbg_webdata_transfer.c, $ext_shared) fi PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE" diff --git b/sapi/phpdbg/config.w32 a/sapi/phpdbg/config.w32 index 6f0bd8f..651c7e6 100644 --- b/sapi/phpdbg/config.w32 +++ a/sapi/phpdbg/config.w32 @@ -1,5 +1,6 @@ ARG_ENABLE('phpdbg', 'Build phpdbg', 'no'); ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no'); +ARG_ENABLE('phpdbgwebhelper', 'Build phpdbg webhelper', 'yes'); PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' + 'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' + @@ -14,6 +15,10 @@ if (PHP_PHPDBG == "yes") { ADD_FLAG("LIBS_PHPDBG", "ws2_32.lib user32.lib"); ADD_FLAG("CFLAGS_PHPDBG", "/D YY_NO_UNISTD_H"); ADD_FLAG("LDFLAGS_PHPDBG", "/stack:8388608"); + + if (PHP_PHPDBGWEBHELPER == "yes") { + EXTENSION('phpdbg-webhelper', 'phpdbg_rinit_hook.c phpdbg_webdata_compress.c'); + } } if (PHP_PHPDBGS == "yes") { diff --git b/sapi/phpdbg/phpdbg.c a/sapi/phpdbg/phpdbg.c index 9c56b1d..5ebc203 100644 --- b/sapi/phpdbg/phpdbg.c +++ a/sapi/phpdbg/phpdbg.c @@ -1039,13 +1039,7 @@ int main(int argc, char **argv) /* {{{ */ zend_bool remote = 0; int step = 0; zend_phpdbg_globals *settings = NULL; - -#ifdef _WIN32 - char *bp_tmp_file = NULL; -#else - char bp_tmp_file[] = "/tmp/phpdbg.XXXXXX"; -#endif - + char *bp_tmp = NULL; char *address; int listen = -1; int server = -1; @@ -1081,29 +1075,6 @@ int main(int argc, char **argv) /* {{{ */ #endif phpdbg_main: - if (!cleaning) { - -#ifdef _WIN32 - bp_tmp_file = malloc(L_tmpnam); - - if (bp_tmp_file) { - if (!tmpnam(bp_tmp_file)) { - free(bp_tmp_file); - bp_tmp_file = NULL; - } - } - - if (!bp_tmp_file) { - phpdbg_error("tmpfile", "", "Unable to create temporary file"); - return 1; - } -#else - if (!mkstemp(bp_tmp_file)) { - memset(bp_tmp_file, 0, sizeof(bp_tmp_file)); - } -#endif - - } ini_entries = NULL; ini_entries_len = 0; ini_ignore = 0; @@ -1466,7 +1437,7 @@ phpdbg_main: if (exec) { /* set execution context */ PHPDBG_G(exec) = phpdbg_resolve_path(exec TSRMLS_CC); - PHPDBG_G(exec_len) = strlen(exec); + PHPDBG_G(exec_len) = PHPDBG_G(exec) ? strlen(PHPDBG_G(exec)) : 0; free(exec); exec = NULL; @@ -1502,9 +1473,13 @@ phpdbg_main: PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; zend_try { phpdbg_init(init_file, init_file_len, init_file_default TSRMLS_CC); - PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; - phpdbg_try_file_init(bp_tmp_file, strlen(bp_tmp_file), 0 TSRMLS_CC); - PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + if (bp_tmp) { + PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; + phpdbg_string_init(bp_tmp TSRMLS_CC); + free(bp_tmp); + bp_tmp = NULL; + PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; + } } zend_end_try(); PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; @@ -1527,29 +1502,32 @@ phpdbg_main: PHPDBG_G(flags) |= PHPDBG_IS_STEPPING; } - if (phpdbg_startup_run) { - zend_try { - PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC); - } zend_end_try(); - if (phpdbg_startup_run > 1) { - /* if -r is on the command line more than once just quit */ - goto phpdbg_out; - } - phpdbg_startup_run = 0; - } - phpdbg_interact: /* phpdbg main() */ do { zend_try { + if (phpdbg_startup_run) { + zend_bool quit_immediately = phpdbg_startup_run > 1; + phpdbg_startup_run = 0; + PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC); + if (quit_immediately) { + /* if -r is on the command line more than once just quit */ + EG(bailout) = __orig_bailout; /* reset zend_try */ + break; + } + } + phpdbg_interactive(1 TSRMLS_CC); } zend_catch { if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) { - FILE *bp_tmp_fp = fopen(bp_tmp_file, "w"); + char *bp_tmp_str; PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; - phpdbg_export_breakpoints(bp_tmp_fp TSRMLS_CC); + phpdbg_export_breakpoints_to_string(&bp_tmp_str TSRMLS_CC); PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT; - fclose(bp_tmp_fp); + if (bp_tmp_str) { + bp_tmp = strdup(bp_tmp_str); + efree(bp_tmp_str); + } cleaning = 1; } else { cleaning = 0; @@ -1689,11 +1667,5 @@ phpdbg_out: free(PHPDBG_G(sapi_name_ptr)); } -#ifdef _WIN32 - free(bp_tmp_file); -#else - unlink(bp_tmp_file); -#endif - return 0; } /* }}} */ diff --git b/sapi/phpdbg/phpdbg_bp.c a/sapi/phpdbg/phpdbg_bp.c index cf28a33..33824d4 100644 --- b/sapi/phpdbg/phpdbg_bp.c +++ a/sapi/phpdbg/phpdbg_bp.c @@ -111,10 +111,19 @@ PHPDBG_API void phpdbg_reset_breakpoints(TSRMLS_D) /* {{{ */ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ { + char *string; + phpdbg_export_breakpoints_to_string(&string TSRMLS_CC); + fputs(string, handle); +} + +PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str TSRMLS_DC) /* {{{ */ +{ HashPosition position[2]; HashTable **table = NULL; zend_ulong id = 0L; + *str = ""; + if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) { phpdbg_notice("exportbreakpoint", "count=\"%d\"", "Exporting %d breakpoints", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])); /* this only looks like magic, it isn't */ @@ -126,55 +135,57 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], NULL, NULL, &id, 0, &position[0]); for (zend_hash_internal_pointer_reset_ex((*table), &position[1]); - zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS; - zend_hash_move_forward_ex((*table), &position[1])) { + zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS; + zend_hash_move_forward_ex((*table), &position[1])) { if (brake->id == id) { + char *new_str = NULL; + switch (brake->type) { case PHPDBG_BREAK_FILE: { - fprintf(handle, - "break %s:%lu\n", + phpdbg_asprintf(&new_str, + "%sbreak %s:%lu\n", *str, ((phpdbg_breakfile_t*)brake)->filename, ((phpdbg_breakfile_t*)brake)->line); } break; case PHPDBG_BREAK_SYM: { - fprintf(handle, - "break %s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s\n", *str, ((phpdbg_breaksymbol_t*)brake)->symbol); } break; case PHPDBG_BREAK_METHOD: { - fprintf(handle, - "break %s::%s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s::%s\n", *str, ((phpdbg_breakmethod_t*)brake)->class_name, ((phpdbg_breakmethod_t*)brake)->func_name); } break; case PHPDBG_BREAK_METHOD_OPLINE: { - fprintf(handle, - "break %s::%s#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s::%s#%ld\n", *str, ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_FUNCTION_OPLINE: { - fprintf(handle, - "break %s#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s#%ld\n", *str, ((phpdbg_breakopline_t*)brake)->func_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_FILE_OPLINE: { - fprintf(handle, - "break %s:#%ld\n", + phpdbg_asprintf(&new_str, + "%sbreak %s:#%ld\n", *str, ((phpdbg_breakopline_t*)brake)->class_name, ((phpdbg_breakopline_t*)brake)->opline_num); } break; case PHPDBG_BREAK_OPCODE: { - fprintf(handle, - "break %s\n", + phpdbg_asprintf(&new_str, + "%sbreak %s\n", *str, ((phpdbg_breakop_t*)brake)->name); } break; @@ -184,20 +195,20 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ if (conditional->paramed) { switch (conditional->param.type) { case STR_PARAM: - fprintf(handle, - "break at %s if %s\n", conditional->param.str, conditional->code); + phpdbg_asprintf(&new_str, + "%sbreak at %s if %s\n", *str, conditional->param.str, conditional->code); break; case METHOD_PARAM: - fprintf(handle, - "break at %s::%s if %s\n", + phpdbg_asprintf(&new_str, + "%sbreak at %s::%s if %s\n", *str, conditional->param.method.class, conditional->param.method.name, conditional->code); break; case FILE_PARAM: - fprintf(handle, - "break at %s:%lu if %s\n", + phpdbg_asprintf(&new_str, + "%sbreak at %s:%lu if %s\n", *str, conditional->param.file.name, conditional->param.file.line, conditional->code); break; @@ -205,15 +216,23 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */ default: { /* do nothing */ } break; } } else { - fprintf( - handle, "break if %s\n", conditional->code); + phpdbg_asprintf(&new_str, "%sbreak if %s\n", str, conditional->code); } } break; } + + if ((*str)[0]) { + efree(*str); + } + *str = new_str; } } } } + + if (!(*str)[0]) { + *str = NULL; + } } /* }}} */ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */ @@ -232,6 +251,8 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML } path_len = strlen(path); + phpdbg_debug("file path: %s, resolved path: %s, was compiled: %d\n", original_path, path, zend_hash_exists(&PHPDBG_G(file_sources), path, path_len)); + if (!zend_hash_exists(&PHPDBG_G(file_sources), path, path_len)) { if (php_stream_stat_path(path, &ssb) == FAILURE) { if (original_path[0] == '/') { @@ -246,6 +267,8 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML } else if (!(ssb.sb.st_mode & (S_IFREG|S_IFLNK))) { phpdbg_error("breakpoint", "type=\"notregular\" add=\"fail\" file=\"%s\"", "Cannot set breakpoint in %s, it is not a regular file", path); return; + } else { + phpdbg_debug("File exists, but not compiled\n"); } } @@ -273,9 +296,13 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(file_sources), &position); zend_hash_get_current_key_ex(&PHPDBG_G(file_sources), &file, &filelen, NULL, 0, &position) == HASH_KEY_IS_STRING; zend_hash_move_forward_ex(&PHPDBG_G(file_sources), &position)) { - if (!(pending = ((broken = phpdbg_resolve_pending_file_break_ex(file, filelen, path, path_len, broken TSRMLS_CC)) == NULL))) { + HashTable *fileht; + + phpdbg_debug("Compare against loaded %s\n", file); + + if (!(pending = ((fileht = phpdbg_resolve_pending_file_break_ex(file, filelen, path, path_len, broken TSRMLS_CC)) == NULL))) { phpdbg_breakfile_t *brake; - zend_hash_index_find(broken, line_num, (void **) &brake); + zend_hash_index_find(fileht, line_num, (void **) &brake); new_break = *brake; break; } @@ -298,18 +325,19 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRML PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, const char *cur, uint curlen, HashTable *fileht TSRMLS_DC) /* {{{ */ { - if (curlen < filelen && file[filelen - curlen - 1] == '/' && !memcmp(file + filelen - curlen, cur, curlen)) { + phpdbg_debug("file: %s, filelen: %u, cur: %s, curlen %u, pos: %c, memcmp: %d\n", file, filelen, cur, curlen, filelen > curlen ? file[filelen - curlen - 1] : '?', filelen > curlen ? memcmp(file + filelen - curlen, cur, curlen) : 0); + + if (((curlen < filelen && file[filelen - curlen - 1] == '/') || filelen == curlen) && !memcmp(file + filelen - curlen, cur, curlen)) { phpdbg_breakfile_t *brake, new_brake; HashTable *master = NULL; HashPosition position; - dtor_func_t dtor; PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP; if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, (void **) &master) == FAILURE) { - dtor = PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING].pDestructor; - PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING].pDestructor = NULL; - zend_hash_add(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, fileht, sizeof(HashTable), (void **) &fileht); + HashTable new_ht; + zend_hash_init(&new_ht, 8, NULL, phpdbg_file_breaks_dtor, 0); + zend_hash_add(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, &new_ht, sizeof(HashTable), (void **) &master); } for (zend_hash_internal_pointer_reset_ex(fileht, &position); @@ -322,24 +350,18 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin if (master) { zend_hash_index_update(master, brake->line, (void **) &new_brake, sizeof(phpdbg_breakfile_t), NULL); PHPDBG_BREAK_MAPPING(brake->id, master); - } else { - efree((char *) brake->filename); - *brake = new_brake; - PHPDBG_BREAK_MAPPING(brake->id, fileht); } } zend_hash_del(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur, curlen); - if (!master) { - PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING].pDestructor = dtor; - } - if (!zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING])) { PHPDBG_G(flags) &= ~PHPDBG_HAS_PENDING_FILE_BP; } - return fileht; + phpdbg_debug("compiled file: %s, cur bp file: %s\n", file, cur); + + return master; } return NULL; @@ -351,6 +373,8 @@ PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file TSRMLS_DC) /* HashTable *fileht; uint filelen = strlen(file); + phpdbg_debug("was compiled: %s\n", file); + zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], &position); while (zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], (void**) &fileht, &position) == SUCCESS) { const char *cur; @@ -359,6 +383,8 @@ PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file TSRMLS_DC) /* zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], (char **) &cur, &curlen, NULL, 0, &position); zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], &position); + phpdbg_debug("check bp: %s\n", cur); + phpdbg_resolve_pending_file_break_ex(file, filelen, cur, curlen, fileht TSRMLS_CC); } } @@ -877,10 +903,21 @@ static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_ { HashTable *breaks; phpdbg_breakbase_t *brake; - size_t name_len = strlen(op_array->filename); + size_t path_len; + char realpath[MAXPATHLEN]; + const char *path = op_array->filename; + + if (VCWD_REALPATH(path, realpath)) { + path = realpath; + } + + path_len = strlen(path); + +#if 0 + phpdbg_debug("Op at: %.*s %d\n", path_len, path, (*EG(opline_ptr))->lineno); +#endif - if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], op_array->filename, - name_len, (void**)&breaks) == FAILURE) { + if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], path, path_len, (void**)&breaks) == FAILURE) { return NULL; } diff --git b/sapi/phpdbg/phpdbg_bp.h a/sapi/phpdbg/phpdbg_bp.h index eca5953..63a9961 100644 --- b/sapi/phpdbg/phpdbg_bp.h +++ a/sapi/phpdbg/phpdbg_bp.h @@ -157,6 +157,7 @@ PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id TSRMLS_DC); PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable ***table, HashPosition *position TSRMLS_DC); /* }}} */ /* {{{ Breakpoint Exportation API */ -PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC); /* }}} */ +PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC); +PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str TSRMLS_DC); /* }}} */ #endif /* PHPDBG_BP_H */ diff --git b/sapi/phpdbg/phpdbg_io.c a/sapi/phpdbg/phpdbg_io.c index 6908a68..a2a5c59 100644 --- b/sapi/phpdbg/phpdbg_io.c +++ a/sapi/phpdbg/phpdbg_io.c @@ -187,10 +187,6 @@ PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_DC PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len TSRMLS_DC) { - if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { - return 0; - } - if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { return phpdbg_send_bytes(sock, ptr, len); } diff --git b/sapi/phpdbg/phpdbg_out.c a/sapi/phpdbg/phpdbg_out.c index 365708c..7e1dc7b 100644 --- b/sapi/phpdbg/phpdbg_out.c +++ a/sapi/phpdbg/phpdbg_out.c @@ -1168,6 +1168,10 @@ PHPDBG_API int phpdbg_output_err_buf(const char *tag, const char *xmlfmt, const va_list args; int errbuf_active = PHPDBG_G(err_buf).active; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + PHPDBG_G(err_buf).active = 0; #ifdef ZTS @@ -1188,6 +1192,10 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, int fd, const char *tag, const c va_list args; int len; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + va_start(args, strfmt); len = phpdbg_vprint(type TSRMLS_CC, fd, tag, xmlfmt, strfmt, args); va_end(args); @@ -1198,6 +1206,10 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, int fd, const char *tag, const c PHPDBG_API int phpdbg_xml_internal(int fd TSRMLS_DC, const char *fmt, ...) { int len = 0; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { va_list args; char *buffer; @@ -1243,6 +1255,10 @@ PHPDBG_API int phpdbg_out_internal(int fd TSRMLS_DC, const char *fmt, ...) { int buflen; int len = 0; + if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) { + return 0; + } + va_start(args, fmt); buflen = phpdbg_xml_vasprintf(&buffer, fmt, 0, args TSRMLS_CC); va_end(args); diff --git b/sapi/phpdbg/phpdbg_prompt.c a/sapi/phpdbg/phpdbg_prompt.c index 73ecbcb..c1fcb59 100644 --- b/sapi/phpdbg/phpdbg_prompt.c +++ a/sapi/phpdbg/phpdbg_prompt.c @@ -208,98 +208,128 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ * return FAILURE; } /* }}} */ -void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ -{ - struct stat sb; +struct phpdbg_init_state { + int line; + zend_bool in_code; + char *code; + size_t code_len; + const char *init_file; +}; - if (init_file && VCWD_STAT(init_file, &sb) != -1) { - FILE *fp = fopen(init_file, "r"); - if (fp) { - int line = 1; +static void phpdbg_line_init(char *cmd, struct phpdbg_init_state *state TSRMLS_DC) { + size_t cmd_len = strlen(cmd); - char cmd[PHPDBG_MAX_CMD]; - size_t cmd_len = 0L; - char *code = NULL; - size_t code_len = 0L; - zend_bool in_code = 0; + state->line++; - while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { - cmd_len = strlen(cmd)-1; - - while (cmd_len > 0L && isspace(cmd[cmd_len-1])) - cmd_len--; - - cmd[cmd_len] = '\0'; - - if (*cmd && cmd_len > 0L && cmd[0] != '#') { - if (cmd_len == 2) { - if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { - in_code = 1; - goto next_line; - } else { - if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { - in_code = 0; - code[code_len] = '\0'; - { - zend_eval_stringl(code, code_len, NULL, "phpdbginit code" TSRMLS_CC); - } - free(code); - code = NULL; - goto next_line; - } - } - } + while (cmd_len > 0L && isspace(cmd[cmd_len-1])) { + cmd_len--; + } - if (in_code) { - if (code == NULL) { - code = malloc(cmd_len + 1); - } else code = realloc(code, code_len + cmd_len + 1); + cmd[cmd_len] = '\0'; - if (code) { - memcpy( - &code[code_len], cmd, cmd_len); - code_len += cmd_len; - } - goto next_line; - } + if (*cmd && cmd_len > 0L && cmd[0] != '#') { + if (cmd_len == 2) { + if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) { + state->in_code = 1; + return; + } else { + if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) { + state->in_code = 0; + state->code[state->code_len] = '\0'; + zend_eval_stringl(state->code, state->code_len, NULL, "phpdbginit code" TSRMLS_CC); + free(state->code); + state->code = NULL; + return; + } + } + } - zend_try { - char *input = phpdbg_read_input(cmd TSRMLS_CC); - phpdbg_param_t stack; + if (state->in_code) { + if (state->code == NULL) { + state->code = malloc(cmd_len + 1); + } else { + state->code = realloc(state->code, state->code_len + cmd_len + 1); + } - phpdbg_init_param(&stack, STACK_PARAM); + if (state->code) { + memcpy(&state->code[state->code_len], cmd, cmd_len); + state->code_len += cmd_len; + } - phpdbg_activate_err_buf(1 TSRMLS_CC); + return; + } - if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { - switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */ TSRMLS_CC)) { - case FAILURE: - phpdbg_activate_err_buf(0 TSRMLS_CC); - if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { - phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!" TSRMLS_CC, init_file, line, input); - } - break; - } - } + zend_try { + char *input = phpdbg_read_input(cmd TSRMLS_CC); + phpdbg_param_t stack; + + phpdbg_init_param(&stack, STACK_PARAM); + + phpdbg_activate_err_buf(1 TSRMLS_CC); + if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) { + switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */ TSRMLS_CC)) { + case FAILURE: phpdbg_activate_err_buf(0 TSRMLS_CC); - phpdbg_free_err_buf(TSRMLS_C); - - phpdbg_stack_free(&stack); - phpdbg_destroy_input(&input TSRMLS_CC); - } zend_catch { - PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); - if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { - zend_bailout(); + if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { + if (state->init_file) { + phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!" TSRMLS_CC, state->init_file, state->line, input); + } else { + phpdbg_output_err_buf("initfailure", "%b line=\"%d\" input=\"%s\"", "Unrecognized command on line %d: %s, %b!" TSRMLS_CC, state->line, input); + } } - } zend_end_try(); + break; } -next_line: - line++; } - if (code) { - free(code); + phpdbg_activate_err_buf(0 TSRMLS_CC); + phpdbg_free_err_buf(TSRMLS_C); + + phpdbg_stack_free(&stack); + phpdbg_destroy_input(&input TSRMLS_CC); + } zend_catch { + PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING); + if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + zend_bailout(); + } + } zend_end_try(); + } + +} + +void phpdbg_string_init(char *buffer TSRMLS_DC) { + struct phpdbg_init_state state = {0}; + char *str = strtok(buffer, "\n"); + + while (str) { + phpdbg_line_init(str, &state TSRMLS_CC); + + str = strtok(NULL, "\n"); + } + + if (state.code) { + free(state.code); + } +} + +void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */ +{ + struct stat sb; + + if (init_file && VCWD_STAT(init_file, &sb) != -1) { + FILE *fp = fopen(init_file, "r"); + if (fp) { + char cmd[PHPDBG_MAX_CMD]; + struct phpdbg_init_state state = {0}; + + state.init_file = init_file; + + while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) { + phpdbg_line_init(cmd, &state TSRMLS_CC); + } + + if (state.code) { + free(state.code); } fclose(fp); @@ -676,10 +706,10 @@ PHPDBG_COMMAND(run) /* {{{ */ EG(active_op_array) = orig_op_array; EG(opline_ptr) = orig_opline; EG(return_value_ptr_ptr) = orig_retval_ptr; - - phpdbg_clean(1 TSRMLS_CC); } + phpdbg_clean(1 TSRMLS_CC); + PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING; } else { phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!"); @@ -1132,7 +1162,7 @@ PHPDBG_COMMAND(register) /* {{{ */ phpdbg_notice("register", "function=\"%s\"", "Registered %s", lcname); } else { - phpdbg_error("register", "type=\"notfoundc\" function=\"%s\"", "The requested function (%s) could not be found", param->str); + phpdbg_error("register", "type=\"notfound\" function=\"%s\"", "The requested function (%s) could not be found", param->str); } } else { phpdbg_error("register", "type=\"inuse\" function=\"%s\"", "The requested name (%s) is already in use", lcname); diff --git b/sapi/phpdbg/phpdbg_prompt.h a/sapi/phpdbg/phpdbg_prompt.h index 94e24df..f583f2c 100644 --- b/sapi/phpdbg/phpdbg_prompt.h +++ a/sapi/phpdbg/phpdbg_prompt.h @@ -22,6 +22,7 @@ #define PHPDBG_PROMPT_H /* {{{ */ +void phpdbg_string_init(char *buffer TSRMLS_DC); void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC); void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC); int phpdbg_interactive(zend_bool allow_async_unsafe TSRMLS_DC); diff --git b/sapi/phpdbg/phpdbg_rinit_hook.c a/sapi/phpdbg/phpdbg_rinit_hook.c index 049a782..acbdfb6 100644 --- b/sapi/phpdbg/phpdbg_rinit_hook.c +++ a/sapi/phpdbg/phpdbg_rinit_hook.c @@ -99,3 +99,7 @@ zend_module_entry phpdbg_webhelper_module_entry = { PHPDBG_VERSION, STANDARD_MODULE_PROPERTIES }; + +#ifdef COMPILE_DL_PHPDBG_WEBHELPER +ZEND_GET_MODULE(phpdbg_webhelper) +#endif diff --git b/sapi/phpdbg/phpdbg_wait.c a/sapi/phpdbg/phpdbg_wait.c index ea506a2..95024b8 100644 --- b/sapi/phpdbg/phpdbg_wait.c +++ a/sapi/phpdbg/phpdbg_wait.c @@ -18,11 +18,10 @@ #include "phpdbg_wait.h" #include "phpdbg_prompt.h" -#include "ext/json/JSON_parser.h" +#include "ext/standard/php_var.h" #include "ext/standard/basic_functions.h" ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -ZEND_EXTERN_MODULE_GLOBALS(json); static void phpdbg_rebuild_http_globals_array(int type, const char *name TSRMLS_DC) { zval **zvpp; @@ -127,16 +126,18 @@ static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval ***ptr) { } void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { -#ifdef HAVE_JSON zval *free_zv = NULL; - zval zv, **zvpp; + zval zv, *zvp = &zv, **zvpp; HashTable *ht; - php_json_decode(&zv, msg, len, 1, 1000 /* enough */ TSRMLS_CC); + php_unserialize_data_t var_hash; - if (JSON_G(error_code) != PHP_JSON_ERROR_NONE) { - phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed JSON was sent to this socket, arborting"); + PHP_VAR_UNSERIALIZE_INIT(var_hash); + if (!php_var_unserialize(&zvp, (const unsigned char **) &msg, (unsigned char *) msg + len, &var_hash TSRMLS_CC)) { + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed serialized was sent to this socket, arborting"); return; } + PHP_VAR_UNSERIALIZE_DESTROY(var_hash); ht = Z_ARRVAL(zv); @@ -172,6 +173,7 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { free_zv = *zvpp; } +#if PHP_VERSION_ID >= 50600 if (zend_hash_find(ht, "input", sizeof("input"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_STRING) { if (SG(request_info).request_body) { php_stream_close(SG(request_info).request_body); @@ -180,6 +182,7 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { php_stream_truncate_set_size(SG(request_info).request_body, 0); php_stream_write(SG(request_info).request_body, Z_STRVAL_PP(zvpp), Z_STRLEN_PP(zvpp)); } +#endif if (zend_hash_find(ht, "cwd", sizeof("cwd"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_STRING) { if (VCWD_CHDIR(Z_STRVAL_PP(zvpp)) == SUCCESS) { @@ -358,12 +361,10 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { /* Reapply raw input */ /* ??? */ -#endif } PHPDBG_COMMAND(wait) /* {{{ */ { -#ifdef HAVE_JSON struct sockaddr_un local, remote; int rlen, sr, sl; unlink(PHPDBG_G(socket_path)); @@ -415,5 +416,4 @@ PHPDBG_COMMAND(wait) /* {{{ */ phpdbg_notice("wait", "import=\"success\"", "Successfully imported request data, stopped before executing"); return SUCCESS; -#endif } /* }}} */ diff --git b/sapi/phpdbg/phpdbg_webdata_transfer.c a/sapi/phpdbg/phpdbg_webdata_transfer.c index e7438ea..7c169ee 100644 --- b/sapi/phpdbg/phpdbg_webdata_transfer.c +++ a/sapi/phpdbg/phpdbg_webdata_transfer.c @@ -17,11 +17,9 @@ */ #include "phpdbg_webdata_transfer.h" -#include "ext/json/php_json.h" +#include "ext/standard/php_var.h" PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { -#ifdef HAVE_JSON - smart_str buf = {0}; zval array; HashTable *ht; /* I really need to change that to an array of zvals... */ @@ -51,6 +49,7 @@ PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { zend_hash_add(ht, "GLOBALS", sizeof("GLOBALS"), &zvp1, sizeof(zval *), NULL); } +#if PHP_VERSION_ID >= 50600 /* save php://input */ { php_stream *stream; @@ -66,6 +65,7 @@ PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { Z_SET_REFCOUNT(zv2, 2); zend_hash_add(ht, "input", sizeof("input"), &zvp2, sizeof(zval *), NULL); } +#endif /* change sapi name */ { @@ -177,9 +177,17 @@ PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len TSRMLS_DC) { } /* encode data */ - php_json_encode(&buf, &array, 0 TSRMLS_CC); - *msg = buf.c; - *len = buf.len; + { + php_serialize_data_t var_hash; + smart_str buf = {0}; + zval *arrayptr = &array; + + PHP_VAR_SERIALIZE_INIT(var_hash); + php_var_serialize(&buf, &arrayptr, &var_hash TSRMLS_CC); + PHP_VAR_SERIALIZE_DESTROY(var_hash); + *msg = buf.c; + *len = buf.len; + } + zval_dtor(&array); -#endif }