Skip to content
This repository
Browse code

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 authored January 31, 2011
10  engine/lib/configuration.php
@@ -37,8 +37,16 @@ function unset_config($name, $site_guid = 0) {
37 37
 function set_config($name, $value, $site_guid = 0) {
38 38
 	global $CONFIG;
39 39
 
  40
+	$name = trim($name);
  41
+
  42
+	// cannot store anything longer than 32 characters in db, so catch before we set
  43
+	if (elgg_strlen($name) > 32) {
  44
+		elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
  45
+		return false;
  46
+	}
  47
+
40 48
 	// Unset existing
41  
-	unset_config($name,$site_guid);
  49
+	unset_config($name, $site_guid);
42 50
 
43 51
 	$name = sanitise_string($name);
44 52
 	$value = sanitise_string($value);
34  engine/lib/elgglib.php
@@ -1080,7 +1080,7 @@ function __elgg_php_exception_handler($exception) {
1080 1080
  * Get the value of a particular piece of data in the datalist
1081 1081
  *
1082 1082
  * @param string $name The name of the datalist
1083  
- * @return string|false Depending on success
  1083
+ * @return string|null|false String if value exists, null if doesn't, false on error
1084 1084
  */
1085 1085
 function datalist_get($name) {
1086 1086
 	global $CONFIG, $DATALIST_CACHE;
@@ -1090,6 +1090,14 @@ function datalist_get($name) {
1090 1090
 		return false;
1091 1091
 	}
1092 1092
 
  1093
+	$name = trim($name);
  1094
+
  1095
+	// cannot store anything longer than 32 characters in db, so catch here
  1096
+	if (elgg_strlen($name) > 32) {
  1097
+		elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
  1098
+		return false;
  1099
+	}
  1100
+
1093 1101
 	$name = sanitise_string($name);
1094 1102
 	if (isset($DATALIST_CACHE[$name])) {
1095 1103
 		return $DATALIST_CACHE[$name];
@@ -1135,7 +1143,7 @@ function datalist_get($name) {
1135 1143
 		return $row->value;
1136 1144
 	}*/
1137 1145
 
1138  
-	return false;
  1146
+	return null;
1139 1147
 }
1140 1148
 
1141 1149
 /**
@@ -1143,12 +1151,20 @@ function datalist_get($name) {
1143 1151
  *
1144 1152
  * @param string $name The name of the datalist
1145 1153
  * @param string $value The new value
1146  
- * @return true
  1154
+ * @return bool
1147 1155
  */
1148 1156
 function datalist_set($name, $value) {
1149 1157
 
1150 1158
 	global $CONFIG, $DATALIST_CACHE;
1151 1159
 
  1160
+	$name = trim($name);
  1161
+
  1162
+	// cannot store anything longer than 32 characters in db, so catch before we set
  1163
+	if (elgg_strlen($name) > 32) {
  1164
+		elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
  1165
+		return false;
  1166
+	}
  1167
+
1152 1168
 	$name = sanitise_string($name);
1153 1169
 	$value = sanitise_string($value);
1154 1170
 
@@ -1162,7 +1178,6 @@ function datalist_set($name, $value) {
1162 1178
 		$datalist_memcache->delete($name);
1163 1179
 	}
1164 1180
 
1165  
-	//delete_data("delete from {$CONFIG->dbprefix}datalists where name = '{$name}'");
1166 1181
 	insert_data("INSERT into {$CONFIG->dbprefix}datalists set name = '{$name}', value = '{$value}' ON DUPLICATE KEY UPDATE value='{$value}'");
1167 1182
 
1168 1183
 	$DATALIST_CACHE[$name] = $value;
@@ -1176,15 +1191,22 @@ function datalist_set($name, $value) {
1176 1191
  * if the function was executed before or on $timelastupdatedcheck, this
1177 1192
  * function will run it again.
1178 1193
  *
  1194
+ * @warning The function name cannot be longer than 32 characters long due to
  1195
+ * the current schema for the datalist table.
  1196
+ *
1179 1197
  * @param string $functionname The name of the function you want to run.
1180 1198
  * @param int $timelastupdatedcheck Optionally, the UNIX epoch timestamp of the execution threshold
1181 1199
  * @return true|false Depending on success.
1182 1200
  */
1183 1201
 function run_function_once($functionname, $timelastupdatedcheck = 0) {
1184  
-	if ($lastupdated = datalist_get($functionname)) {
  1202
+	$lastupdated = datalist_get($functionname);
  1203
+	if ($lastupdated) {
1185 1204
 		$lastupdated = (int) $lastupdated;
1186  
-	} else {
  1205
+	} elseif ($lastupdated !== false) {
1187 1206
 		$lastupdated = 0;
  1207
+	} else {
  1208
+		// unable to check datalist
  1209
+		return false;
1188 1210
 	}
1189 1211
 	if (is_callable($functionname) && $lastupdated <= $timelastupdatedcheck) {
1190 1212
 		$functionname();

0 notes on commit 757e128

Please sign in to comment.
Something went wrong with that request. Please try again.