Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent variable_init from retuning an empty array. #37

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c2f92a3
Issue by mikeytown2: prevent variable_init from returning a blank array.
mikeytown2 Mar 29, 2012
0883914
Merge remote-tracking branch 'upstream/master'
Mar 19, 2013
855b220
Issue #939810 by mikeytown2: Notice: Undefined index: key in format_x…
Mar 19, 2013
0fb3577
Issue #557542 by mikeytown2, c960657, catch, & glennpratt: Cache modu…
Mar 19, 2013
707636f
Issue #1317236 by mikeytown2: Race condition in file_delete: Warning:…
Mar 19, 2013
cdbd300
Issue #1004820 by mikeytown2: Notice: Undefined index: type in dblog_…
Mar 19, 2013
71e7146
Issue #134204 by mikeytown2: Optimize element_children()
Mar 19, 2013
e909d96
Issue #753064 by mikeytown2: _menu_link_translate() might avoid calli…
Mar 19, 2013
471dea8
Issue #261148 by mikeytown2, catch, chx: menu_masks variable is empty…
Mar 19, 2013
9c92a1a
Issue #1688282 by mikeytown2:
Mar 19, 2013
9325a37
Issue #521838 by mikeytown2: Speedup/Clean up drupal_get_schema_versi…
Mar 19, 2013
a506b7d
Issue #1710656 by mikeytown2: If item is hidden in _menu_tree_check_a…
Mar 19, 2013
280a930
Issue #352180 by scor: Better, multi-site friendly www. addition/remo…
Mar 19, 2013
1bfe877
Issue #764726 by mikeytown2: hook_taxonomy_term_presave() is missing
Mar 19, 2013
4b90144
Issue #496184 by mikeytown2: db_set_active errors out if db_connect f…
Mar 19, 2013
91e2070
Issue #961908 by mikeytown2: Make drupal_attributes() faster
Mar 19, 2013
c2da748
Issue #1103910 by mikeytown2, catch: bootstrap_invoke_all() queries b…
Mar 19, 2013
9a5b2d4
Issue #1345402 by mikeytown2, catch: Backport DRUPAL_ROOT to 6.x
Mar 19, 2013
d9f1d55
Issue #1080964 by catch: Be more sparing with locale cache clears
Mar 19, 2013
e08f3da
Issue #960056 by cedarm: trigger_get_assigned_actions() has no static…
Mar 19, 2013
470a314
Issue #353595 by hefox: node_access issues four queries on default in…
Mar 19, 2013
ba7c5b5
Issue #163018 by catch: taxonomy_get_vocabularies needs static caching.
Mar 19, 2013
932f132
Issue #196862 by mikeytown2: COUNT(*) is an expensive query in InnoDB.
Mar 19, 2013
907a84c
Issue #818818 by mikeytown2: Race Condition when using file_save_data…
Mar 19, 2013
895f06d
Issue #667714 by mikeytown2, tinker: Impossible to insert serialized …
Mar 19, 2013
a1ef2cd
Issue #972528 by mikeytown2, mkalkbrenner: dblog fails to log MAX_ALL…
Mar 19, 2013
0dcfca3
Issue #360377 by janusman: book_get_books() cache becomes stale when …
Mar 19, 2013
7d8cdc5
Issue #476048 by mikeytown2: MySQL transient error handling
Mar 19, 2013
cb7df7a
php 5.4 fixes
Mar 22, 2013
f949838
Fix file mode
Mar 22, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ DirectoryIndex index.php
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment and adapt the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
Expand Down
7 changes: 6 additions & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* Handles incoming requests to fire off regularly-scheduled tasks (cron jobs).
*/

include_once './includes/bootstrap.inc';
/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());

include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_cron_run();
4 changes: 2 additions & 2 deletions includes/batch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function _batch_process() {
// request, we check if it requires an additional file for functions
// definitions.
if ($set_changed && isset($current_set['file']) && is_file($current_set['file'])) {
include_once($current_set['file']);
include_once DRUPAL_ROOT . '/' . $current_set['file'];
}

$finished = 1;
Expand Down Expand Up @@ -295,7 +295,7 @@ function _batch_finished() {
if (isset($batch_set['finished'])) {
// Check if the set requires an additional file for functions definitions.
if (isset($batch_set['file']) && is_file($batch_set['file'])) {
include_once($batch_set['file']);
include_once DRUPAL_ROOT . '/' . $batch_set['file'];
}
if (function_exists($batch_set['finished'])) {
$batch_set['finished']($batch_set['success'], $batch_set['results'], $batch_set['operations']);
Expand Down
105 changes: 63 additions & 42 deletions includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ function conf_path($require_settings = TRUE, $reset = FALSE) {
for ($i = count($uri) - 1; $i > 0; $i--) {
for ($j = count($server); $j > 0; $j--) {
$dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
if (file_exists("$confdir/$dir/settings.php") || (!$require_settings && file_exists("$confdir/$dir"))) {
if (file_exists(DRUPAL_ROOT . "/$confdir/$dir/settings.php") || (!$require_settings && file_exists(DRUPAL_ROOT . "/$confdir/$dir"))) {
$conf = "$confdir/$dir";
return $conf;
}
Expand Down Expand Up @@ -407,8 +407,8 @@ function conf_init() {
$_SERVER['HTTP_HOST'] = '';
}

if (file_exists('./'. conf_path() .'/settings.php')) {
include_once './'. conf_path() .'/settings.php';
if (file_exists(DRUPAL_ROOT . '/'. conf_path() .'/settings.php')) {
include_once DRUPAL_ROOT . '/'. conf_path() .'/settings.php';
}

// Ignore the placeholder URL from default.settings.php.
Expand Down Expand Up @@ -520,7 +520,7 @@ function drupal_get_filename($type, $name, $filename = NULL) {
$files[$type] = array();
}

if (!empty($filename) && file_exists($filename)) {
if (!empty($filename) && file_exists(DRUPAL_ROOT . '/'. $filename)) {
$files[$type][$name] = $filename;
}
elseif (isset($files[$type][$name])) {
Expand All @@ -530,7 +530,7 @@ function drupal_get_filename($type, $name, $filename = NULL) {
// the database. This is required because this function is called both
// before we have a database connection (i.e. during installation) and
// when a database connection fails.
elseif (db_is_active() && (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file))) {
elseif (db_is_active() && (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists(DRUPAL_ROOT . '/'. $file))) {
$files[$type][$name] = $file;
}
else {
Expand All @@ -541,7 +541,7 @@ function drupal_get_filename($type, $name, $filename = NULL) {
$file = (($type == 'theme_engine') ? "$name.engine" : "$name.$type");

foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
if (file_exists($file)) {
if (file_exists(DRUPAL_ROOT . '/'. $file)) {
$files[$type][$name] = $file;
break;
}
Expand All @@ -561,13 +561,21 @@ function drupal_get_filename($type, $name, $filename = NULL) {
* file.
*/
function variable_init($conf = array(), $regenerate = FALSE, $recursion_depth = 0) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
// NOTE: caching the variables improves performance by 20% when serving
// cached pages.
if (!$regenerate && $cached = cache_get('variables', 'cache')) {
$variables = $cached->data;
}
else {
if (defined('MAINTENANCE_MODE') || lock_acquire('variable_cache_regenerate')) {
$result = db_query('SELECT * FROM {variable}');
// Exit here if the database went away. Do not want to pollute the cache
// with bad data. This request isn't going to end well anyway; end it
// eairly.
if ($result === FALSE) {
// This function calls exit.
_db_error_page();
}
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
Expand All @@ -580,15 +588,27 @@ function variable_init($conf = array(), $regenerate = FALSE, $recursion_depth =
// Wait for another request that is already doing this work.
lock_wait('variable_cache_regenerate');

// Run the function again. Try a limited number of times to avoid
// infinite recursion if the database connection is invalid for
// Run the function again. Try a limited number of times to avoid
// infinite recursion if the database connection is invalid for
// some reason, e.g., mysqld restart, loss of network, etc.
$recursion_depth++;
if ($recursion_depth < 50) {
return variable_init($conf, $regenerate, $recursion_depth);
}

$variables = array();
// If the recursion_depth hit the limit, assume we aren't going to get it
// from the cache or the lock will be released any time soon. Give up and
// get variables from the database.
$result = db_query('SELECT * FROM {variable}');
// Exit here if the database went away. Do not want to pollute the cache
// with bad data. This request isn't going to end well.
if ($result === FALSE) {
// This function calls exit.
_db_error_page();
}
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
}
}

Expand Down Expand Up @@ -653,7 +673,7 @@ function variable_set($name, $value) {
if (is_string($db_prefix) && strpos($db_prefix, 'simpletest') === 0) {
cache_clear_all('variables', 'cache');
}

variable_cache_rebuild();
}

Expand Down Expand Up @@ -682,7 +702,7 @@ function variable_del($name) {
if (is_string($db_prefix) && strpos($db_prefix, 'simpletest') === 0) {
cache_clear_all('variables', 'cache');
}

variable_cache_rebuild();
}

Expand Down Expand Up @@ -747,7 +767,11 @@ function drupal_page_is_cacheable($force = NULL) {
* The name of the bootstrap hook we wish to invoke.
*/
function bootstrap_invoke_all($hook) {
foreach (module_list(TRUE, TRUE) as $module) {
static $bootstrap_modules;
if (!isset($bootstrap_modules)) {
$bootstrap_modules = module_list(TRUE, TRUE);
}
foreach ($bootstrap_modules as $module) {
drupal_load('module', $module);
module_invoke($module, $hook);
}
Expand Down Expand Up @@ -775,7 +799,7 @@ function drupal_load($type, $name) {
$filename = drupal_get_filename($type, $name);

if ($filename) {
include_once "./$filename";
include_once DRUPAL_ROOT . "/$filename";
$files[$type][$name] = TRUE;

return TRUE;
Expand Down Expand Up @@ -805,7 +829,7 @@ function drupal_set_header($name = NULL, $value = NULL, $append = FALSE) {
if (!isset($name)) {
return $headers;
}

// Support the Drupal 6 header API
if (!isset($value)) {
if (strpos($name, ':') !== FALSE) {
Expand Down Expand Up @@ -1423,7 +1447,7 @@ function drupal_bootstrap($phase = NULL) {
_drupal_bootstrap($current_phase);
}
}

return $phase_index;
}

Expand Down Expand Up @@ -1453,7 +1477,7 @@ function _drupal_bootstrap($phase) {
case DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE:
// Allow specifying special cache handlers in settings.php, like
// using memcached or files for storing cache information.
require_once variable_get('cache_inc', './includes/cache.inc');
require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');
// If the page_cache_fastpath is set to TRUE in settings.php and
// page_cache_fastpath (implemented in the special implementation of
// cache.inc) printed the page and indicated this with a returned TRUE
Expand All @@ -1477,13 +1501,13 @@ function _drupal_bootstrap($phase) {
}

// Initialize the default database.
require_once './includes/database.inc';
require_once DRUPAL_ROOT . '/includes/database.inc';
db_set_active();
// Allow specifying alternate lock implementations in settings.php, like
// those using APC or memcached.
require_once variable_get('lock_inc', './includes/lock.inc');
require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc');
lock_init();

// Detect if an installation is present.
detect_installation_or_run_installer();

Expand All @@ -1499,7 +1523,7 @@ function _drupal_bootstrap($phase) {
break;

case DRUPAL_BOOTSTRAP_SESSION:
require_once variable_get('session_inc', './includes/session.inc');
require_once DRUPAL_ROOT . '/' . variable_get('session_inc', 'includes/session.inc');
drupal_session_initialize();
break;

Expand All @@ -1519,7 +1543,7 @@ function _drupal_bootstrap($phase) {
// If the skipping of the bootstrap hooks is not enforced, call hook_init.
if (!is_object($cache) || $cache_mode != CACHE_AGGRESSIVE) {
// Load module handling.
require_once './includes/module.inc';
require_once DRUPAL_ROOT . '/includes/module.inc';
bootstrap_invoke_all('boot');
}

Expand All @@ -1534,11 +1558,11 @@ function _drupal_bootstrap($phase) {
// We are done.
exit;
}

if (!$cache && drupal_page_is_cacheable() && $cache_mode != CACHE_EXTERNAL) {
header('X-Drupal-Cache: MISS');
}

// If using an external cache and the page is cacheable, set headers.
if ($cache_mode == CACHE_EXTERNAL && drupal_page_is_cacheable()) {
drupal_page_cache_header_external();
Expand All @@ -1556,13 +1580,13 @@ function _drupal_bootstrap($phase) {
break;

case DRUPAL_BOOTSTRAP_PATH:
require_once './includes/path.inc';
require_once DRUPAL_ROOT . '/includes/path.inc';
// Initialize $_GET['q'] prior to loading modules and invoking hook_init().
drupal_init_path();
break;

case DRUPAL_BOOTSTRAP_FULL:
require_once './includes/common.inc';
require_once DRUPAL_ROOT . '/includes/common.inc';
_drupal_bootstrap_full();
break;
}
Expand All @@ -1577,7 +1601,7 @@ function _drupal_bootstrap($phase) {
* @see _drupal_maintenance_theme()
*/
function drupal_maintenance_theme() {
require_once './includes/theme.maintenance.inc';
require_once DRUPAL_ROOT . '/includes/theme.maintenance.inc';
_drupal_maintenance_theme();
}

Expand Down Expand Up @@ -1605,7 +1629,7 @@ function drupal_init_language() {
$language = language_default();
}
else {
include_once './includes/language.inc';
include_once DRUPAL_ROOT . '/includes/language.inc';
$language = language_initialize();
}
}
Expand Down Expand Up @@ -1679,17 +1703,17 @@ function ip_address() {

if (!isset($ip_address)) {
$ip_address = $_SERVER['REMOTE_ADDR'];

// Only use parts of the X-Forwarded-For (XFF) header that have followed a trusted route.
// Specifically, identify the leftmost IP address in the XFF header that is not one of ours.
// An XFF header is: X-Forwarded-For: client1, proxy1, proxy2
if (isset($_SERVER['HTTP_' . variable_get('x_forwarded_for_header', 'X_FORWARDED_FOR')]) && variable_get('reverse_proxy', 0)) {
// Load trusted reverse proxy server IPs.
$reverse_proxy_addresses = variable_get('reverse_proxy_addresses', array());

// Turn XFF header into an array.
$forwarded = explode(',', $_SERVER['HTTP_' . variable_get('x_forwarded_for_header', 'X_FORWARDED_FOR')]);

// Trim the forwarded IPs; they may have been delimited by commas and spaces.
$forwarded = array_map('trim', $forwarded);

Expand All @@ -1698,7 +1722,7 @@ function ip_address() {

// Eliminate all trusted IPs.
$untrusted = array_diff($forwarded, $reverse_proxy_addresses);

// The right-most IP is the most specific we can trust.
$ip_address = array_pop($untrusted);
}
Expand All @@ -1712,9 +1736,9 @@ function ip_address() {
*/
function drupal_session_initialize() {
global $user;

session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy_sid', 'sess_gc');

if (isset($_COOKIE[session_name()])) {
// If a session cookie exists, initialize the session. Otherwise the
// session is only started on demand in drupal_session_commit(), making
Expand Down Expand Up @@ -1776,7 +1800,7 @@ function drupal_session_commit() {

/**
* Return whether a session has been started.
*/
*/
function drupal_session_started($set = NULL) {
static $session_started = FALSE;
if (isset($set)) {
Expand Down Expand Up @@ -1841,7 +1865,7 @@ function drupal_save_session($status = NULL) {
}
return $save_session;
}

/**
* Returns the current bootstrap phase for this Drupal process.
*
Expand All @@ -1865,8 +1889,7 @@ function drupal_valid_test_ua($user_agent) {
// We use the database credentials from settings.php to make the HMAC key, since
// the database is not yet initialized and we can't access any Drupal variables.
// The file properties add more entropy not easily accessible to others.
// $filepath = DRUPAL_ROOT . '/includes/bootstrap.inc';
$filepath = './includes/bootstrap.inc';
$filepath = DRUPAL_ROOT . '/includes/bootstrap.inc';
// $key = sha1(serialize($databases) . filectime($filepath) . fileinode($filepath), TRUE);
$key = sha1(serialize($db_url) . filectime($filepath) . fileinode($filepath), TRUE);
// The HMAC must match.
Expand All @@ -1885,9 +1908,7 @@ function drupal_generate_test_ua($prefix) {
// We use the database credentials to make the HMAC key, since we
// check the HMAC before the database is initialized. filectime()
// and fileinode() are not easily determined from remote.
// $filepath = DRUPAL_ROOT . '/includes/bootstrap.inc';
$filepath = './includes/bootstrap.inc';
// $key = sha1(serialize($databases) . filectime($filepath) . fileinode($filepath), TRUE);
$filepath = DRUPAL_ROOT . '/includes/bootstrap.inc';
$key = sha1(serialize($db_url) . filectime($filepath) . fileinode($filepath), TRUE);
}
// Generate a moderately secure HMAC based on the database credentials.
Expand All @@ -1914,7 +1935,7 @@ function drupal_is_cli() {
*/
function drupal_session_destroy() {
session_destroy();

// Workaround PHP 5.2 fatal error "Failed to initialize storage module".
// @see http://bugs.php.net/bug.php?id=32330
session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy_sid', 'sess_gc');
Expand Down
Loading