validateClasses($data) ) { return FALSE; } } else { // It's not a string - give it back return $data; } $old_cb = ini_get('unserialize_callback_func'); ini_set('unserialize_callback_func','JPSpan_Unserializer_PHP_Callback'); $result = @unserialize($data); ini_set('unserialize_callback_func',$old_cb); // Check for a serialized FALSE value if ( $result !== FALSE || $data == 'b:0;' ) { return $result; } return $data; } /** * Validates unserialized data, checking the class names of serialized objects, * to prevent unexpected objects from being instantiated by PHP's unserialize() * @param mixed data to validate * @return boolean TRUE if valid * @access private */ function validateClasses($data) { foreach ( $this->getClasses($data) as $class ) { if ( !array_key_exists(strtolower($class),$GLOBALS['_JPSPAN_UNSERIALIZER_MAP']) ) { trigger_error('Illegal type: '.strtolower($class),E_USER_ERROR); return FALSE; } } return TRUE; } /** * Parses the serialized string, extracting class names * @param string serialized string to parse * @return array list of classes found * @access private */ function getClasses($string) { // Stip any string representations (which might contain object syntax) $string = preg_replace('/s:[0-9]+:".*"/Us','',$string); // Pull out the class named preg_match_all('/O:[0-9]+:"(.*)"/U',$string,$matches,PREG_PATTERN_ORDER); // Make sure names are unique (same object serialized twice) return array_unique($matches[1]); } }