summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2013-08-05 01:36:56 -0400
committerDavid Rothstein <drothstein@gmail.com>2013-08-05 01:36:56 -0400
commitf019275be7d960060c682c69d462832fd53e02f2 (patch)
tree9e8d7628db1e35ff295d0d604e6203a4e0b81213 /includes
parent7a036f167854456ce49f167094a9965958e5bb2e (diff)
downloadbrdo-f019275be7d960060c682c69d462832fd53e02f2.tar.gz
brdo-f019275be7d960060c682c69d462832fd53e02f2.tar.bz2
Issue #238250 by markpavlitski | Xano: Fixed cache_clear_all()('*', 'block', TRUE); will TRUNCATE the {block} table without additional checks.
Diffstat (limited to 'includes')
-rw-r--r--includes/cache.inc32
1 files changed, 31 insertions, 1 deletions
diff --git a/includes/cache.inc b/includes/cache.inc
index c2a514646..c2f9569f5 100644
--- a/includes/cache.inc
+++ b/includes/cache.inc
@@ -501,7 +501,16 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
else {
if ($wildcard) {
if ($cid == '*') {
- db_truncate($this->bin)->execute();
+ // Check if $this->bin is a cache table before truncating. Other
+ // cache_clear_all() operations throw a PDO error in this situation,
+ // so we don't need to verify them first. This ensures that non-cache
+ // tables cannot be truncated accidentally.
+ if ($this->isValidBin()) {
+ db_truncate($this->bin)->execute();
+ }
+ else {
+ throw new Exception(t('Invalid or missing cache bin specified: %bin', array('%bin' => $this->bin)));
+ }
}
else {
db_delete($this->bin)
@@ -538,4 +547,25 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
->fetchField();
return empty($result);
}
+
+ /**
+ * Checks if $this->bin represents a valid cache table.
+ *
+ * This check is required to ensure that non-cache tables are not truncated
+ * accidentally when calling cache_clear_all().
+ *
+ * @return boolean
+ */
+ function isValidBin() {
+ if ($this->bin == 'cache' || substr($this->bin, 0, 6) == 'cache_') {
+ // Skip schema check for bins with standard table names.
+ return TRUE;
+ }
+ // These fields are required for any cache table.
+ $fields = array('cid', 'data', 'expire', 'created', 'serialized');
+ // Load the table schema.
+ $schema = drupal_get_schema($this->bin);
+ // Confirm that all fields are present.
+ return isset($schema['fields']) && !array_diff($fields, array_keys($schema['fields']));
+ }
}