From 7359dd6df3bd39a3aea3d27054ec639c687a24a3 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 15 Jan 2014 12:12:22 +0400 Subject: [PATCH 1/2] Log information about cached scripts and keys --- ext/opcache/ZendAccelerator.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index e9616b89eb..d174f2a42f 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1112,7 +1112,9 @@ static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_ha char *new_key = zend_shared_alloc(key_length + 1); if (new_key) { memcpy(new_key, key, key_length + 1); - zend_accel_hash_update(&ZCSG(hash), new_key, key_length + 1, 1, bucket); + if (zend_accel_hash_update(&ZCSG(hash), new_key, key_length + 1, 1, bucket)) { + zend_accel_error(ACCEL_LOG_INFO, "Added key '%s'", new_key); + } } else { zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM TSRMLS_CC); } @@ -1196,16 +1198,21 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr /* store script structure in the hash table */ bucket = zend_accel_hash_update(&ZCSG(hash), new_persistent_script->full_path, new_persistent_script->full_path_len + 1, 0, new_persistent_script); - if (bucket && !ZCG(accel_directives).revalidate_path && - /* key may contain non-persistent PHAR aliases (see issues #115 and #149) */ - memcmp(key, "phar://", sizeof("phar://") - 1) != 0 && - (new_persistent_script->full_path_len != key_length || - memcmp(new_persistent_script->full_path, key, key_length) != 0)) { - /* link key to the same persistent script in hash table */ - if (!zend_accel_hash_update(&ZCSG(hash), key, key_length + 1, 1, bucket)) { - zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!"); - ZSMMG(memory_exhausted) = 1; - zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH TSRMLS_CC); + if (bucket) { + zend_accel_error(ACCEL_LOG_INFO, "Cached script '%s'", new_persistent_script->full_path); + if (!ZCG(accel_directives).revalidate_path && + /* key may contain non-persistent PHAR aliases (see issues #115 and #149) */ + memcmp(key, "phar://", sizeof("phar://") - 1) != 0 && + (new_persistent_script->full_path_len != key_length || + memcmp(new_persistent_script->full_path, key, key_length) != 0)) { + /* link key to the same persistent script in hash table */ + if (zend_accel_hash_update(&ZCSG(hash), key, key_length + 1, 1, bucket)) { + zend_accel_error(ACCEL_LOG_INFO, "Added key '%s'", key); + } else { + zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!"); + ZSMMG(memory_exhausted) = 1; + zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH TSRMLS_CC); + } } } From 5662ffb295c6f9cb10768d8246f2656aae6b8abb Mon Sep 17 00:00:00 2001 From: Conor McDermottroe Date: Tue, 14 Jan 2014 02:08:13 +0000 Subject: [PATCH 2/2] Bug #66481 Segfaults on session_name() If the previous value of session.name was NULL then any call to session_name($string) would result in a segmentation fault. This changes the behaviour to set the value of session.name to "PHPSESSID" if a blank value is given in php.ini or via -d on the command line. There is already protection against setting it to NULL via session_name() or ini_set(). --- ext/session/session.c | 7 +++++++ ext/session/tests/bug66481.phpt | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 ext/session/tests/bug66481.phpt diff --git a/ext/session/session.c b/ext/session/session.c index 35db50ae64..5ea38475db 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -617,6 +617,13 @@ static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */ static PHP_INI_MH(OnUpdateName) /* {{{ */ { + /* Don't accept a blank session name from php.ini or -d session.name= */ + if (!PG(modules_activated) && !new_value_length) { + /* Force the default value. */ + new_value = "PHPSESSID"; + new_value_length = 9; + } + /* Numeric session.name won't work at all */ if (PG(modules_activated) && (!new_value_length || is_numeric_string(new_value, new_value_length, NULL, NULL, 0))) { diff --git a/ext/session/tests/bug66481.phpt b/ext/session/tests/bug66481.phpt new file mode 100644 index 0000000000..0479b5ff4d --- /dev/null +++ b/ext/session/tests/bug66481.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #66481: Calls to session_name() segfault when session.name is null. +--INI-- +session.name= +--SKIPIF-- + +--FILE-- +