From a0974f2d5946d96ef41281830ce614f64ab58408 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 11 Jul 2011 10:31:49 +0000 Subject: [PATCH] Fixed bug #54305 (Crash in gc_remove_zval_from_buffer) --- Zend/tests/bug54305.phpt | 22 ++++++++++++++++ Zend/zend_vm_def.h | 14 +++++++--- Zend/zend_vm_execute.h | 56 ++++++++++++++++++++++++++++------------ 3 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 Zend/tests/bug54305.phpt diff --git a/Zend/tests/bug54305.phpt b/Zend/tests/bug54305.phpt new file mode 100644 index 00000000000..8e85d2be58e --- /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 aad9585a8ff..cdc6456282b 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 99a939644b6..039d199d474 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); }