From bb719aee8c209c53730d4ce0e31a4e3d419b33cf Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Fri, 7 Jan 2022 12:32:05 -0500 Subject: [PATCH] update version of extlib/bootstrap.inc there is a newer version in upstream Drupal --- extlib/bootstrap.inc | 165 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 143 insertions(+), 22 deletions(-) diff --git a/extlib/bootstrap.inc b/extlib/bootstrap.inc index 87f62a6..ce2c617 100644 --- a/extlib/bootstrap.inc +++ b/extlib/bootstrap.inc @@ -8,7 +8,7 @@ /** * The current system version. */ -define('VERSION', '7.70'); +define('VERSION', '7.83'); /** * Core API compatibility. @@ -359,6 +359,7 @@ abstract class DrupalCacheArray implements ArrayAccess { /** * Implements ArrayAccess::offsetExists(). */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return $this->offsetGet($offset) !== NULL; } @@ -366,6 +367,7 @@ abstract class DrupalCacheArray implements ArrayAccess { /** * Implements ArrayAccess::offsetGet(). */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { if (isset($this->storage[$offset]) || array_key_exists($offset, $this->storage)) { return $this->storage[$offset]; @@ -378,6 +380,7 @@ abstract class DrupalCacheArray implements ArrayAccess { /** * Implements ArrayAccess::offsetSet(). */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->storage[$offset] = $value; } @@ -385,6 +388,7 @@ abstract class DrupalCacheArray implements ArrayAccess { /** * Implements ArrayAccess::offsetUnset(). */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->storage[$offset]); } @@ -803,14 +807,7 @@ function drupal_settings_initialize() { // HTTP_HOST can be modified by a visitor, but we already sanitized it // in drupal_settings_initialize(). if (!empty($_SERVER['HTTP_HOST'])) { - $cookie_domain = $_SERVER['HTTP_HOST']; - // Strip leading periods, www., and port numbers from cookie domain. - $cookie_domain = ltrim($cookie_domain, '.'); - if (strpos($cookie_domain, 'www.') === 0) { - $cookie_domain = substr($cookie_domain, 4); - } - $cookie_domain = explode(':', $cookie_domain); - $cookie_domain = '.' . $cookie_domain[0]; + $cookie_domain = _drupal_get_cookie_domain($_SERVER['HTTP_HOST']); } } // Per RFC 2109, cookie domains must contain at least one dot other than the @@ -831,6 +828,24 @@ function drupal_settings_initialize() { session_name($prefix . substr(hash('sha256', $session_name), 0, 32)); } +/** + * Derive the cookie domain to use for session cookies. + * + * @param $host + * The value of the HTTP host name. + * + * @return + * The string to use as a cookie domain. + */ +function _drupal_get_cookie_domain($host) { + $cookie_domain = $host; + // Strip leading periods and port numbers from cookie domain. + $cookie_domain = ltrim($cookie_domain, '.'); + $cookie_domain = explode(':', $cookie_domain); + $cookie_domain = '.' . $cookie_domain[0]; + return $cookie_domain; +} + /** * Returns and optionally sets the filename for a system resource. * @@ -1157,6 +1172,31 @@ function _drupal_trigger_error_with_delayed_logging($error_msg, $error_type = E_ $delay_logging = FALSE; } +/** + * Invoke trigger_error() using a fatal error that will terminate the request. + * + * Normally, Drupal's error handler does not terminate script execution on + * user-level errors, even if the error is of type E_USER_ERROR. This function + * triggers an error of type E_USER_ERROR that is explicitly forced to be a + * fatal error which terminates script execution. + * + * @param string $error_msg + * The error message to trigger. As with trigger_error() itself, this is + * limited to 1024 bytes; additional characters beyond that will be removed. + * + * @see _drupal_error_handler_real() + */ +function drupal_trigger_fatal_error($error_msg) { + $fatal_error = &drupal_static(__FUNCTION__, FALSE); + $fatal_error = TRUE; + trigger_error($error_msg, E_USER_ERROR); + $fatal_error = FALSE; + // The standard Drupal error handler should have treated this as a fatal + // error and already ended the page request. But in case another error + // handler is being used, terminate execution explicitly here also. + exit; +} + /** * Writes the file scan cache to the persistent cache. * @@ -1189,19 +1229,21 @@ function variable_initialize($conf = array()) { $variables = $cached->data; } else { - // Cache miss. Avoid a stampede. + // Cache miss. Avoid a stampede by acquiring a lock. If the lock fails to + // acquire, optionally just continue with uncached processing. $name = 'variable_init'; - if (!lock_acquire($name, 1)) { - // Another request is building the variable cache. - // Wait, then re-run this function. + $lock_acquired = lock_acquire($name, 1); + if (!$lock_acquired && variable_get('variable_initialize_wait_for_lock', FALSE)) { lock_wait($name); return variable_initialize($conf); } else { - // Proceed with variable rebuild. + // Load the variables from the table. $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed()); - cache_set('variables', $variables, 'cache_bootstrap'); - lock_release($name); + if ($lock_acquired) { + cache_set('variables', $variables, 'cache_bootstrap'); + lock_release($name); + } } } @@ -2263,7 +2305,7 @@ function drupal_random_bytes($count) { // $random_state does not use drupal_static as it stores random bytes. static $random_state, $bytes, $has_openssl; - $missing_bytes = $count - strlen($bytes); + $missing_bytes = $count - strlen((string) $bytes); if ($missing_bytes > 0) { // PHP versions prior 5.3.4 experienced openssl_random_pseudo_bytes() @@ -2594,13 +2636,10 @@ function drupal_get_hash_salt() { * The filename that the error was raised in. * @param $line * The line number the error was raised at. - * @param $context - * An array that points to the active symbol table at the point the error - * occurred. */ -function _drupal_error_handler($error_level, $message, $filename, $line, $context) { +function _drupal_error_handler($error_level, $message, $filename, $line) { require_once DRUPAL_ROOT . '/includes/errors.inc'; - _drupal_error_handler_real($error_level, $message, $filename, $line, $context); + _drupal_error_handler_real($error_level, $message, $filename, $line); } /** @@ -3877,3 +3916,85 @@ function drupal_clear_opcode_cache($filepath) { @apc_delete_file($filepath); } } + +/** + * Drupal's wrapper around PHP's setcookie() function. + * + * This allows the cookie's $value and $options to be altered. + * + * @param $name + * The name of the cookie. + * @param $value + * The value of the cookie. + * @param $options + * An associative array which may have any of the keys expires, path, domain, + * secure, httponly, samesite. + * + * @see setcookie() + * @ingroup php_wrappers + */ +function drupal_setcookie($name, $value, $options) { + $options = _drupal_cookie_params($options); + if (\PHP_VERSION_ID >= 70300) { + setcookie($name, $value, $options); + } + else { + setcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']); + } +} + +/** + * Process the params for cookies. This emulates support for the SameSite + * attribute in earlier versions of PHP, and allows the value of that attribute + * to be overridden. + * + * @param $options + * An associative array which may have any of the keys expires, path, domain, + * secure, httponly, samesite. + * + * @return + * An associative array which may have any of the keys expires, path, domain, + * secure, httponly, and samesite. + */ +function _drupal_cookie_params($options) { + $options['samesite'] = _drupal_samesite_cookie($options); + if (\PHP_VERSION_ID < 70300) { + // Emulate SameSite support in older PHP versions. + if (!empty($options['samesite'])) { + // Ensure the SameSite attribute is only added once. + if (!preg_match('/SameSite=/i', $options['path'])) { + $options['path'] .= '; SameSite=' . $options['samesite']; + } + } + } + return $options; +} + +/** + * Determine the value for the samesite cookie attribute, in the following order + * of precedence: + * + * 1) A value explicitly passed to drupal_setcookie() + * 2) A value set in $conf['samesite_cookie_value'] + * 3) The setting from php ini + * 4) The default of None, or FALSE (no attribute) if the cookie is not Secure + * + * @param $options + * An associative array as passed to drupal_setcookie(). + * @return + * The value for the samesite cookie attribute. + */ +function _drupal_samesite_cookie($options) { + if (isset($options['samesite'])) { + return $options['samesite']; + } + $override = variable_get('samesite_cookie_value', NULL); + if ($override !== NULL) { + return $override; + } + $ini_options = session_get_cookie_params(); + if (isset($ini_options['samesite'])) { + return $ini_options['samesite']; + } + return empty($options['secure']) ? FALSE : 'None'; +} -- 2.25.1