From a0aff5860499e1df814b14a94dcdcd0558fa0d2e Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 9 Feb 2016 12:11:41 +0100 Subject: [PATCH] Fix bug where some database column length limit could be exceeded (#5291) Which cased e.g. sql errors when creating a contact group with name > 255 characters. --- plugins/libkolab/lib/kolab_storage_cache_contact.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/libkolab/lib/kolab_storage_cache_contact.php b/plugins/libkolab/lib/kolab_storage_cache_contact.php index d526a0e7..70aa5f62 100644 --- a/plugins/libkolab/lib/kolab_storage_cache_contact.php +++ b/plugins/libkolab/lib/kolab_storage_cache_contact.php @@ -23,8 +23,9 @@ class kolab_storage_cache_contact extends kolab_storage_cache { - protected $extra_cols = array('type','name','firstname','surname','email'); - protected $binary_items = array( + protected $extra_cols_max = 255; + protected $extra_cols = array('type','name','firstname','surname','email'); + protected $binary_items = array( 'photo' => '|[^;]+;base64,([^<]+)|i', 'pgppublickey' => '|data:application/pgp-keys;base64,([^<]+)|i', 'pkcs7publickey' => '|data:application/pkcs7-mime;base64,([^<]+)|i', @@ -59,6 +60,13 @@ class kolab_storage_cache_contact extends kolab_storage_cache $sql_data['name'] = rcube_charset::clean($object['organization']); } + // make sure some data is not longer that database limit (#5291) + foreach ($this->extra_cols as $col) { + if (strlen($sql_data[$col]) > $this->extra_cols_max) { + $sql_data[$col] = rcube_charset::clean(substr($sql_data[$col], 0, $this->extra_cols_max)); + } + } + return $sql_data; } } \ No newline at end of file