Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #2793 added logic to handle variable names longer than 32 chara…

…cters

git-svn-id: http://code.elgg.org/elgg/branches/1.7@7961 36083f99-b078-4883-b0ff-0f9b5a30f544
  • Loading branch information...
commit 757e12830c36470db31a11b5567c0acdc9c48ed4 1 parent d7e9736
Cash Costello cash authored
Showing with 37 additions and 7 deletions.
  1. +9 −1 engine/lib/configuration.php
  2. +28 −6 engine/lib/elgglib.php
10 engine/lib/configuration.php
View
@@ -37,8 +37,16 @@ function unset_config($name, $site_guid = 0) {
function set_config($name, $value, $site_guid = 0) {
global $CONFIG;
+ $name = trim($name);
+
+ // cannot store anything longer than 32 characters in db, so catch before we set
+ if (elgg_strlen($name) > 32) {
+ elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
+ return false;
+ }
+
// Unset existing
- unset_config($name,$site_guid);
+ unset_config($name, $site_guid);
$name = sanitise_string($name);
$value = sanitise_string($value);
34 engine/lib/elgglib.php
View
@@ -1080,7 +1080,7 @@ function __elgg_php_exception_handler($exception) {
* Get the value of a particular piece of data in the datalist
*
* @param string $name The name of the datalist
- * @return string|false Depending on success
+ * @return string|null|false String if value exists, null if doesn't, false on error
*/
function datalist_get($name) {
global $CONFIG, $DATALIST_CACHE;
@@ -1090,6 +1090,14 @@ function datalist_get($name) {
return false;
}
+ $name = trim($name);
+
+ // cannot store anything longer than 32 characters in db, so catch here
+ if (elgg_strlen($name) > 32) {
+ elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
+ return false;
+ }
+
$name = sanitise_string($name);
if (isset($DATALIST_CACHE[$name])) {
return $DATALIST_CACHE[$name];
@@ -1135,7 +1143,7 @@ function datalist_get($name) {
return $row->value;
}*/
- return false;
+ return null;
}
/**
@@ -1143,12 +1151,20 @@ function datalist_get($name) {
*
* @param string $name The name of the datalist
* @param string $value The new value
- * @return true
+ * @return bool
*/
function datalist_set($name, $value) {
global $CONFIG, $DATALIST_CACHE;
+ $name = trim($name);
+
+ // cannot store anything longer than 32 characters in db, so catch before we set
+ if (elgg_strlen($name) > 32) {
+ elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
+ return false;
+ }
+
$name = sanitise_string($name);
$value = sanitise_string($value);
@@ -1162,7 +1178,6 @@ function datalist_set($name, $value) {
$datalist_memcache->delete($name);
}
- //delete_data("delete from {$CONFIG->dbprefix}datalists where name = '{$name}'");
insert_data("INSERT into {$CONFIG->dbprefix}datalists set name = '{$name}', value = '{$value}' ON DUPLICATE KEY UPDATE value='{$value}'");
$DATALIST_CACHE[$name] = $value;
@@ -1176,15 +1191,22 @@ function datalist_set($name, $value) {
* if the function was executed before or on $timelastupdatedcheck, this
* function will run it again.
*
+ * @warning The function name cannot be longer than 32 characters long due to
+ * the current schema for the datalist table.
+ *
* @param string $functionname The name of the function you want to run.
* @param int $timelastupdatedcheck Optionally, the UNIX epoch timestamp of the execution threshold
* @return true|false Depending on success.
*/
function run_function_once($functionname, $timelastupdatedcheck = 0) {
- if ($lastupdated = datalist_get($functionname)) {
+ $lastupdated = datalist_get($functionname);
+ if ($lastupdated) {
$lastupdated = (int) $lastupdated;
- } else {
+ } elseif ($lastupdated !== false) {
$lastupdated = 0;
+ } else {
+ // unable to check datalist
+ return false;
}
if (is_callable($functionname) && $lastupdated <= $timelastupdatedcheck) {
$functionname();
Please sign in to comment.
Something went wrong with that request. Please try again.