From 074585b68e4efba6b8db15bf1bf762da660b991f Mon Sep 17 00:00:00 2001 From: Niels Heinemann Date: Fri, 20 May 2016 14:29:42 +0200 Subject: [PATCH] Validate user input on stack size --- CRM/Admin/Form/Setting/Miscellaneous.php | 5 +++++ CRM/Utils/Recent.php | 6 +++--- settings/Core.setting.php | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CRM/Admin/Form/Setting/Miscellaneous.php b/CRM/Admin/Form/Setting/Miscellaneous.php index 9f8b189d84..1a092f5b04 100644 --- a/CRM/Admin/Form/Setting/Miscellaneous.php +++ b/CRM/Admin/Form/Setting/Miscellaneous.php @@ -102,6 +102,11 @@ class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting { $errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini."); } + // validate recent items stack size + if ($fields['recentItemsMaxCount'] && ($fields['recentItemsMaxCount'] < 1 || $fields['recentItemsMaxCount'] > CRM_Utils_Recent::MAX_ITEMS)) { + $errors['recentItemsMaxCount'] = ts("Illegal stack size. Use values between 1 and %1.", array( 1 => CRM_Utils_Recent::MAX_ITEMS)); + } + if (!empty($fields['wkhtmltopdfPath'])) { // check and ensure that thi leads to the wkhtmltopdf binary // and it is a valid executable binary diff --git a/CRM/Utils/Recent.php b/CRM/Utils/Recent.php index 659b67381f..c596c7b8cb 100644 --- a/CRM/Utils/Recent.php +++ b/CRM/Utils/Recent.php @@ -40,7 +40,7 @@ class CRM_Utils_Recent { * * @var string */ - const STORE_NAME = 'CRM_Utils_Recent'; + const MAX_ITEMS = 30, STORE_NAME = 'CRM_Utils_Recent'; /** * The list of recently viewed items. @@ -53,14 +53,14 @@ class CRM_Utils_Recent { * Maximum stack size * @var int */ - static private $_maxItems = 20; + static private $_maxItems = 10; /** * Initialize this class and set the static variables. */ public static function initialize() { $maxItemsSetting = Civi::settings()->get('recentItemsMaxCount'); - if (isset($maxItemsSetting) && $maxItemsSetting > 0 && $maxItemsSetting < 100) { + if (isset($maxItemsSetting) && $maxItemsSetting > 0 && $maxItemsSetting < self::MAX_ITEMS) { self::$_maxItems = $maxItemsSetting; } if (!self::$_recent) { diff --git a/settings/Core.setting.php b/settings/Core.setting.php index cb6f090b2b..4137ab7d62 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -839,7 +839,6 @@ return array( 'title' => 'Size of "Recent Items" stack', 'is_domain' => 1, 'is_contact' => 0, - 'description' => 'How many items should CiviCRM store in it\'s "Recently viewed" list.', 'help_text' => NULL, ), 'recentItemsProviders' => array( -- 2.25.1