From: Antony Dovgal Date: Thu, 2 Oct 2008 08:46:04 +0000 (+0000) Subject: use HashPosition to prevent race condition in multithreaded env X-Git-Tag: BEFORE_HEAD_NS_CHANGE~297 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=746aa4485e179fee8d1fea0f941789eca3a81c94;p=php use HashPosition to prevent race condition in multithreaded env --- diff --git a/ext/standard/info.c b/ext/standard/info.c index 667d8a5aef..24ea0fe6ab 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -139,14 +139,16 @@ static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC if (ht) { if (zend_hash_num_elements(ht)) { + HashPosition pos; + if (!sapi_module.phpinfo_as_text) { php_info_printf("Registered %s", name); } else { php_info_printf("\nRegistered %s => ", name); } - zend_hash_internal_pointer_reset(ht); - type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, NULL); + zend_hash_internal_pointer_reset_ex(ht, &pos); + type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos); do { switch (type) { case IS_STRING: @@ -157,8 +159,8 @@ static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC break; } - zend_hash_move_forward(ht); - type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, NULL); + zend_hash_move_forward_ex(ht, &pos); + type = zend_hash_get_current_key_ex(ht, &key, &len, NULL, 0, &pos); if (type == IS_STRING || type == IS_UNICODE) { php_info_print(", "); diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 71857dffcf..5fcae2c19d 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -573,13 +573,14 @@ PHP_FUNCTION(stream_get_transports) } if ((stream_xport_hash = php_stream_xport_get_hash())) { + HashPosition pos; array_init(return_value); - zend_hash_internal_pointer_reset(stream_xport_hash); + zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos); while (zend_hash_get_current_key_ex(stream_xport_hash, &stream_xport, &stream_xport_len, - &num_key, 0, NULL) == HASH_KEY_IS_STRING) { + &num_key, 0, &pos) == HASH_KEY_IS_STRING) { add_next_index_rt_stringl(return_value, stream_xport.s, stream_xport_len - 1, ZSTR_DUPLICATE); - zend_hash_move_forward(stream_xport_hash); + zend_hash_move_forward_ex(stream_xport_hash, &pos); } } else { RETURN_FALSE; @@ -601,10 +602,11 @@ PHP_FUNCTION(stream_get_wrappers) } if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) { + HashPosition pos; array_init(return_value); - for(zend_hash_internal_pointer_reset(url_stream_wrappers_hash); - (key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, NULL)) != HASH_KEY_NON_EXISTANT; - zend_hash_move_forward(url_stream_wrappers_hash)) { + for(zend_hash_internal_pointer_reset_ex(url_stream_wrappers_hash, &pos); + (key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTANT; + zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) { if (key_flags == HASH_KEY_IS_STRING) { add_next_index_rt_stringl(return_value, stream_protocol.s, stream_protocol_len - 1, ZSTR_DUPLICATE); }