From 3ae9c7d69fdaf091e90f5e1145f5f3183d314b35 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 19 Aug 2018 11:03:24 +1000 Subject: [PATCH] Improve type checking in getContactPhone and use CRM_Utils_Request::retrieve to get data from GET Fix retrieving value from GET param as per review by Eileen Replace inserted variables with placeholders as per standards --- CRM/Contact/Page/AJAX.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index f3328e7adb..8ee4f29d43 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -463,34 +463,28 @@ LIMIT {$offset}, {$rowCount} public static function getContactPhone() { $queryString = NULL; + $sqlParmas = []; //check for mobile type $phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name'); $mobileType = CRM_Utils_Array::value('Mobile', $phoneTypes); - $name = CRM_Utils_Array::value('name', $_GET); + $name = CRM_Utils_Request::retrieveValue('name', 'String', NULL, FALSE, 'GET'); if ($name) { - $name = CRM_Utils_Type::escape($name, 'String'); - $queryString = " ( cc.sort_name LIKE '%$name%' OR cp.phone LIKE '%$name%' ) "; + $key = (int) count(array_keys($sqlParmas)) + 1; + $queryString = " ( cc.sort_name LIKE %{$key} OR cp.phone LIKE %{$key} ) "; + $sqlParams[$key] = ['%' . $name . '%', 'String']; } else { - $cid = CRM_Utils_Array::value('cid', $_GET); + $cid = CRM_Utils_Request::retrieveValue('cid', 'CommaSeparatedIntegers', NULL, FALSE, 'GET'); if ($cid) { - //check cid for integer - $contIDS = explode(',', $cid); - foreach ($contIDS as $contID) { - CRM_Utils_Type::escape($contID, 'Integer'); - } $queryString = " cc.id IN ( $cid )"; } } if ($queryString) { $result = array(); - $offset = CRM_Utils_Array::value('offset', $_GET, 0); - $rowCount = CRM_Utils_Array::value('rowcount', $_GET, 20); - - $offset = CRM_Utils_Type::escape($offset, 'Int'); - $rowCount = CRM_Utils_Type::escape($rowCount, 'Int'); + $offset = (int) CRM_Utils_Request::retrieveValue('offset', 'Integer', 0, FALSE, 'GET'); + $rowCount = (int) CRM_Utils_Request::retrieveValue('rowcount', 'Integer', 20, FALSE, 'GET'); // add acl clause here list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc'); @@ -514,7 +508,7 @@ LIMIT {$offset}, {$rowCount} CRM_Utils_Request::retrieve('cid', 'Positive') ); - $dao = CRM_Core_DAO::executeQuery($query); + $dao = CRM_Core_DAO::executeQuery($query, $sqlParams); while ($dao->fetch()) { $result[] = array( -- 2.25.1