Commit 4aee328f authored by mikeytown2's avatar mikeytown2

Issue #2675916 by mikeytown2: Fix DOS issue with the function cache.

parent 0450bdeb
......@@ -3470,7 +3470,6 @@ function httprl_lossless_assoc_array_merge() {
/**
* Run array of data through callback.
*
*
* @param $data
* The data to process.
* @param $callback
......@@ -3581,18 +3580,70 @@ function httprl_call_user_func_array_cache($callback, array $param_arr = array()
) {
// Get all function arguments.
$args = array($callback, $param_arr, $options);
// Set max to zero so this gets regenerated in the background.
$args[2]['cache_lifetime_max'] = 0;
// Also do not skip on a cache miss.
$args[2]['return_null_cache_miss'] = FALSE;
// Call this function again in another process with max lifetime set to
// zero.
httprl_call_user_func_array_async(__FUNCTION__, $args);
_httprl_run_functions_once_on_shutdown_array_cache($args);
}
}
return isset($cache->data) ? $cache->data : NULL;
}
/**
* Cache function helper. Combine duplicates & run them in a shutdown function.
*
* @param callable $args
* The callable to be called.
*/
function _httprl_run_functions_once_on_shutdown_array_cache($args = array()) {
$run_list = &drupal_static('_httprl_run_functions_once_on_shutdown_array_cache', array());
if (!empty($args)) {
if (empty($run_list)) {
// Register a shutdown function is this is the first time being ran.
register_shutdown_function('_httprl_run_functions_once_on_shutdown_array_cache');
}
$run_list[] = $args;
}
else {
unset($args);
$will_run = array();
$already_ran = array();
foreach ($run_list as $args) {
if (empty($args)) {
continue;
}
if (is_string($args[0])) {
$cid = __FUNCTION__ . ':' . $args[0] . ':' . drupal_hash_base64(serialize(array($args[1])));
}
else {
$cid = __FUNCTION__ . ':' . drupal_hash_base64(serialize(array($args[0], $args[1])));
}
if (empty($already_ran[$cid])) {
$already_ran[$cid] = TRUE;
$will_run[] = $args;
}
}
if (!empty($will_run)) {
httprl_call_user_func_array_async('_httprl_run_cache_functions', array($will_run));
}
}
}
/**
* Cache function helper. Runs the array through the cache function.
*
* @param callable $functions_to_cache
* The callable to be called.
*/
function _httprl_run_cache_functions($functions_to_cache) {
foreach ($functions_to_cache as $args) {
// Set max to zero so this gets regenerated in the background.
// Also do not skip on a cache miss.
$args[2]['cache_lifetime_max'] = 0;
$args[2]['return_null_cache_miss'] = FALSE;
call_user_func_array('httprl_call_user_func_array_cache', $args);
}
}
/**
* Get hostname of this server.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment