Browse Source

Fixed possible crash because of race conditions on modifying constants in shared memory

pull/705/head
Dmitry Stogov 12 years ago
parent
commit
2330be5641
  1. 20
      Zend/zend_execute.c
  2. 7
      Zend/zend_vm_def.h
  3. 7
      Zend/zend_vm_execute.h

20
Zend/zend_execute.c

@ -943,6 +943,26 @@ copy_value:
}
}
static void zval_deep_copy(zval **p)
{
zval *value;
ALLOC_ZVAL(value);
*value = **p;
if (Z_TYPE_P(value) == IS_ARRAY) {
HashTable *ht;
ALLOC_HASHTABLE(ht);
zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL_P(value)), NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(ht, Z_ARRVAL_P(value), (copy_ctor_func_t) zval_deep_copy, NULL, sizeof(zval *));
Z_ARRVAL_P(value) = ht;
} else {
zval_copy_ctor(value);
}
INIT_PZVAL(value);
*p = value;
}
/* Utility Functions for Extensions */
static void zend_extension_statement_handler(const zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
{

7
Zend/zend_vm_def.h

@ -3422,6 +3422,13 @@ ZEND_VM_HANDLER(64, ZEND_RECV_INIT, ANY, CONST)
if (IS_CONSTANT_TYPE(Z_TYPE_P(assignment_value))) {
Z_SET_REFCOUNT_P(assignment_value, 1);
zval_update_constant(&assignment_value, 0 TSRMLS_CC);
} else if (Z_TYPE_P(assignment_value) == IS_ARRAY) {
HashTable *ht;
ALLOC_HASHTABLE(ht);
zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL_P(assignment_value)), NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(ht, Z_ARRVAL_P(assignment_value), (copy_ctor_func_t) zval_deep_copy, NULL, sizeof(zval *));
Z_ARRVAL_P(assignment_value) = ht;
} else {
zval_copy_ctor(assignment_value);
}

7
Zend/zend_vm_execute.h

@ -1624,6 +1624,13 @@ static int ZEND_FASTCALL ZEND_RECV_INIT_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_
if (IS_CONSTANT_TYPE(Z_TYPE_P(assignment_value))) {
Z_SET_REFCOUNT_P(assignment_value, 1);
zval_update_constant(&assignment_value, 0 TSRMLS_CC);
} else if (Z_TYPE_P(assignment_value) == IS_ARRAY) {
HashTable *ht;
ALLOC_HASHTABLE(ht);
zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL_P(assignment_value)), NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(ht, Z_ARRVAL_P(assignment_value), (copy_ctor_func_t) zval_deep_copy, NULL, sizeof(zval *));
Z_ARRVAL_P(assignment_value) = ht;
} else {
zval_copy_ctor(assignment_value);
}

Loading…
Cancel
Save