diff --git a/Zend/tests/arg_unpack/many_args.phpt b/Zend/tests/arg_unpack/many_args.phpt new file mode 100644 index 0000000000..0ef5a30d6d --- /dev/null +++ b/Zend/tests/arg_unpack/many_args.phpt @@ -0,0 +1,15 @@ +--TEST-- +Argument unpacking with many arguments +--FILE-- + +--EXPECT-- +int(20000) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 431cd7a4c1..35e337a8e5 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1691,6 +1691,42 @@ static zend_always_inline zend_bool zend_is_by_ref_func_arg_fetch(zend_op *oplin } /* }}} */ +static void **zend_vm_stack_push_args_with_copy(int count TSRMLS_DC) /* {{{ */ +{ + zend_vm_stack p = EG(argument_stack); + + zend_vm_stack_extend(count + 1 TSRMLS_CC); + + EG(argument_stack)->top += count; + *(EG(argument_stack)->top) = (void*)(zend_uintptr_t)count; + while (count-- > 0) { + void *data = *(--p->top); + + if (UNEXPECTED(p->top == ZEND_VM_STACK_ELEMETS(p))) { + zend_vm_stack r = p; + + EG(argument_stack)->prev = p->prev; + p = p->prev; + efree(r); + } + *(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) + count) = data; + } + return EG(argument_stack)->top++; +} +/* }}} */ + +static zend_always_inline void** zend_vm_stack_push_args(int count TSRMLS_DC) /* {{{ */ +{ + if (UNEXPECTED(EG(argument_stack)->top - ZEND_VM_STACK_ELEMETS(EG(argument_stack)) < count) + || UNEXPECTED(EG(argument_stack)->top == EG(argument_stack)->end)) { + return zend_vm_stack_push_args_with_copy(count TSRMLS_CC); + } + *(EG(argument_stack)->top) = (void*)(zend_uintptr_t)count; + return EG(argument_stack)->top++; +} +/* }}} */ + + #define ZEND_VM_NEXT_OPCODE() \ CHECK_SYMBOL_TABLES() \ ZEND_VM_INC_OPCODE(); \ diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index d0a709c2b4..eabe1f1444 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1947,8 +1947,12 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY) } num_args = opline->extended_value + EX(call)->num_additional_args; - EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C); - zend_vm_stack_push((void*)(zend_uintptr_t) num_args TSRMLS_CC); + if (EX(call)->num_additional_args) { + EX(function_state).arguments = zend_vm_stack_push_args(num_args TSRMLS_CC); + } else { + EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C); + zend_vm_stack_push((void*)(zend_uintptr_t) num_args TSRMLS_CC); + } LOAD_OPLINE(); if (fbc->type == ZEND_INTERNAL_FUNCTION) { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index b29a887c3e..e74410b6f9 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -527,8 +527,12 @@ static int ZEND_FASTCALL zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_AR } num_args = opline->extended_value + EX(call)->num_additional_args; - EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C); - zend_vm_stack_push((void*)(zend_uintptr_t) num_args TSRMLS_CC); + if (EX(call)->num_additional_args) { + EX(function_state).arguments = zend_vm_stack_push_args(num_args TSRMLS_CC); + } else { + EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C); + zend_vm_stack_push((void*)(zend_uintptr_t) num_args TSRMLS_CC); + } LOAD_OPLINE(); if (fbc->type == ZEND_INTERNAL_FUNCTION) { diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 4fd16a800a..3020b1bc9c 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1216,7 +1216,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_fstat, 0) ZEND_ARG_INFO(0, fp) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_copy, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_copy, 0, 0, 2) ZEND_ARG_INFO(0, source_file) ZEND_ARG_INFO(0, destination_file) ZEND_ARG_INFO(0, context) diff --git a/ext/standard/tests/file/bug66509.phpt b/ext/standard/tests/file/bug66509.phpt new file mode 100644 index 0000000000..0e414f2321 --- /dev/null +++ b/ext/standard/tests/file/bug66509.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #66509 (copy() showing $context parameter as required) +--FILE-- +getParameters() as $p) { + var_dump($p->isOptional()); +} +?> +--EXPECT-- +bool(false) +bool(false) +bool(true) diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 44656920b7..b98da4ffcd 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -653,8 +653,11 @@ static inline void phpdbg_sigint_handler(int signo) /* {{{ */ PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED; } } else { - PHPDBG_G(flags) |= PHPDBG_IS_QUITTING; - zend_bailout(); + /* we quit remote consoles on recv SIGINT */ + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { + PHPDBG_G(flags) |= PHPDBG_IS_QUITTING; + zend_bailout(); + } } } /* }}} */ @@ -1198,17 +1201,17 @@ phpdbg_main: } zend_end_try(); /* initialize from file */ + PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; zend_try { - PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; phpdbg_init(init_file, init_file_len, init_file_default TSRMLS_CC); phpdbg_try_file_init(bp_tmp_file, strlen(bp_tmp_file), 0 TSRMLS_CC); - PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; - } zend_catch { - PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; - if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { - goto phpdbg_out; - } } zend_end_try(); + PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING; + + /* quit if init says so */ + if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { + goto phpdbg_out; + } /* step from here, not through init */ if (step) { @@ -1235,39 +1238,46 @@ phpdbg_interact: phpdbg_export_breakpoints(bp_tmp_fp TSRMLS_CC); fclose(bp_tmp_fp); cleaning = 1; - goto phpdbg_out; } else { cleaning = 0; } -#ifndef _WIN32 - /* remote client disconnected */ - if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) { - /* renegociate connections */ - phpdbg_open_sockets( - address, listen, &server, &socket, streams); +#ifndef _WIN32 + if (!cleaning) { + /* remote client disconnected */ + if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) { - /* set streams */ - if (streams[0] && streams[1]) { - PHPDBG_G(flags) &= ~PHPDBG_IS_QUITTING; + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { + /* renegociate connections */ + phpdbg_open_sockets( + address, listen, &server, &socket, streams); + + /* set streams */ + if (streams[0] && streams[1]) { + PHPDBG_G(flags) &= ~PHPDBG_IS_QUITTING; + } + + /* this must be forced */ + CG(unclean_shutdown) = 0; + } else { + /* local consoles cannot disconnect, ignore EOF */ + PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED; + } } - - /* this must be forced */ - CG(unclean_shutdown) = 0; } #endif - if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) { - goto phpdbg_out; - } } zend_end_try(); - } while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)); + } while(!cleaning && !(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)); /* this must be forced */ CG(unclean_shutdown) = 0; + /* this is just helpful */ + PG(report_memleaks) = 0; + phpdbg_out: #ifndef _WIN32 - if (PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED) { + if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) { PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED; goto phpdbg_interact; } @@ -1316,7 +1326,7 @@ phpdbg_out: if (cleaning || remote) { goto phpdbg_main; } - + #ifdef ZTS /* bugggy */ /* tsrm_shutdown(); */ diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index ccbbbb8fbd..6f23c4b47b 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -149,7 +149,7 @@ #define PHPDBG_AUTHORS "Felipe Pena, Joe Watkins and Bob Weinand" /* Ordered by last name */ #define PHPDBG_URL "http://phpdbg.com" #define PHPDBG_ISSUES "http://github.com/krakjoe/phpdbg/issues" -#define PHPDBG_VERSION "0.3.0" +#define PHPDBG_VERSION "0.3.1" #define PHPDBG_INIT_FILENAME ".phpdbginit" /* }}} */ diff --git a/sapi/phpdbg/phpdbg_cmd.c b/sapi/phpdbg/phpdbg_cmd.c index a1efac574e..d2aca8caf7 100644 --- a/sapi/phpdbg/phpdbg_cmd.c +++ b/sapi/phpdbg/phpdbg_cmd.c @@ -467,32 +467,43 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */ } if (buffered == NULL) { -#ifndef HAVE_LIBREADLINE - char buf[PHPDBG_MAX_CMD]; - if ((!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && !phpdbg_write(phpdbg_get_prompt(TSRMLS_C))) || - !fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) { - /* the user has gone away */ - phpdbg_error("Failed to read console!"); +disconnect: + if (0) { PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED); zend_bailout(); return NULL; } +#ifndef HAVE_LIBREADLINE + char buf[PHPDBG_MAX_CMD]; + if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { + if (!phpdbg_write(phpdbg_get_prompt(TSRMLS_C))) { + goto disconnect; + } + } + + /* note: EOF is ignored */ +readline: + if (!fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) { + /* the user has gone away */ + if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { + goto disconnect; + } else goto readline; + } + cmd = buf; #else + /* note: EOF makes readline write prompt again in local console mode */ +readline: if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { char buf[PHPDBG_MAX_CMD]; if (fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) { cmd = buf; - } else cmd = NULL; + } else goto disconnect; } else cmd = readline(phpdbg_get_prompt(TSRMLS_C)); if (!cmd) { - /* the user has gone away */ - phpdbg_error("Failed to read console!"); - PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED); - zend_bailout(); - return NULL; + goto readline; } if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) { diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c index 7e64d16d92..50073eb22b 100644 --- a/sapi/phpdbg/phpdbg_opcode.c +++ b/sapi/phpdbg/phpdbg_opcode.c @@ -52,13 +52,15 @@ static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint case IS_VAR: case IS_TMP_VAR: { zend_ulong id = 0, *pid = NULL; - if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &pid) != SUCCESS) { - id = zend_hash_num_elements(vars); - zend_hash_index_update( - vars, (zend_ulong) ops->vars - op->var, - (void**) &id, - sizeof(zend_ulong), NULL); - } else id = *pid; + if (vars != NULL) { + if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &pid) != SUCCESS) { + id = zend_hash_num_elements(vars); + zend_hash_index_update( + vars, (zend_ulong) ops->vars - op->var, + (void**) &id, + sizeof(zend_ulong), NULL); + } else id = *pid; + } asprintf(&decode, "@%lu", id); } break; diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 51b33f7edd..fd51159a87 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -551,7 +551,8 @@ PHPDBG_COMMAND(run) /* {{{ */ zend_op **orig_opline = EG(opline_ptr); zend_op_array *orig_op_array = EG(active_op_array); zval **orig_retval_ptr = EG(return_value_ptr_ptr); - + zend_bool restore = 1; + if (!PHPDBG_G(ops)) { if (phpdbg_compile(TSRMLS_C) == FAILURE) { phpdbg_error("Failed to compile %s, cannot run", PHPDBG_G(exec)); @@ -586,18 +587,19 @@ PHPDBG_COMMAND(run) /* {{{ */ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { phpdbg_error("Caught exit/error from VM"); - goto out; + restore = 0; } } zend_end_try(); - if (EG(exception)) { - phpdbg_handle_exception(TSRMLS_C); + if (restore) { + if (EG(exception)) { + phpdbg_handle_exception(TSRMLS_C); + } + + EG(active_op_array) = orig_op_array; + EG(opline_ptr) = orig_opline; + EG(return_value_ptr_ptr) = orig_retval_ptr; } - - EG(active_op_array) = orig_op_array; - EG(opline_ptr) = orig_opline; - EG(return_value_ptr_ptr) = orig_retval_ptr; - } else { phpdbg_error("Nothing to execute!"); }