From: Dmitry Stogov Date: Mon, 11 Jul 2011 10:31:49 +0000 (+0000) Subject: Fixed bug #54305 (Crash in gc_remove_zval_from_buffer) X-Git-Tag: php-5.4.0alpha2~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a0974f2d5946d96ef41281830ce614f64ab58408;p=php Fixed bug #54305 (Crash in gc_remove_zval_from_buffer) --- diff --git a/Zend/tests/bug54305.phpt b/Zend/tests/bug54305.phpt new file mode 100644 index 0000000000..8e85d2be58 --- /dev/null +++ b/Zend/tests/bug54305.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #54305 (Crash in gc_remove_zval_from_buffer) +--FILE-- + +--EXPECTF-- +Method [ public method methodWithArgs ] { + @@ %sbug54305.php %d - %d + + - Parameters [2] { + Parameter #0 [ $a ] + Parameter #1 [ $b ] + } +} diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index aad9585a8f..cdc6456282 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -982,10 +982,16 @@ ZEND_VM_HANDLER(40, ZEND_ECHO, CONST|TMP|VAR|CV, ANY) if (OP1_TYPE != IS_CONST && UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && - Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); + Z_OBJ_HT_P(z)->get_method != NULL) { + if (OP1_TYPE == IS_TMP_VAR) { + INIT_PZVAL(z); + } + if (zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { + zend_print_variable(&z_copy); + zval_dtor(&z_copy); + } else { + zend_print_variable(z); + } } else { zend_print_variable(z); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 99a939644b..039d199d47 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2012,10 +2012,16 @@ static int ZEND_FASTCALL ZEND_ECHO_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (IS_CONST != IS_CONST && UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && - Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); + Z_OBJ_HT_P(z)->get_method != NULL) { + if (IS_CONST == IS_TMP_VAR) { + INIT_PZVAL(z); + } + if (zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { + zend_print_variable(&z_copy); + zval_dtor(&z_copy); + } else { + zend_print_variable(z); + } } else { zend_print_variable(z); } @@ -6278,10 +6284,16 @@ static int ZEND_FASTCALL ZEND_ECHO_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (IS_TMP_VAR != IS_CONST && UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && - Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); + Z_OBJ_HT_P(z)->get_method != NULL) { + if (IS_TMP_VAR == IS_TMP_VAR) { + INIT_PZVAL(z); + } + if (zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { + zend_print_variable(&z_copy); + zval_dtor(&z_copy); + } else { + zend_print_variable(z); + } } else { zend_print_variable(z); } @@ -10455,10 +10467,16 @@ static int ZEND_FASTCALL ZEND_ECHO_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (IS_VAR != IS_CONST && UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && - Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); + Z_OBJ_HT_P(z)->get_method != NULL) { + if (IS_VAR == IS_TMP_VAR) { + INIT_PZVAL(z); + } + if (zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { + zend_print_variable(&z_copy); + zval_dtor(&z_copy); + } else { + zend_print_variable(z); + } } else { zend_print_variable(z); } @@ -26192,10 +26210,16 @@ static int ZEND_FASTCALL ZEND_ECHO_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (IS_CV != IS_CONST && UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && - Z_OBJ_HT_P(z)->get_method != NULL && - zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - zend_print_variable(&z_copy); - zval_dtor(&z_copy); + Z_OBJ_HT_P(z)->get_method != NULL) { + if (IS_CV == IS_TMP_VAR) { + INIT_PZVAL(z); + } + if (zend_std_cast_object_tostring(z, &z_copy, IS_STRING TSRMLS_CC) == SUCCESS) { + zend_print_variable(&z_copy); + zval_dtor(&z_copy); + } else { + zend_print_variable(z); + } } else { zend_print_variable(z); }