CRM-17984. Ensure input for subtype is valid; if not then do not use it to filter...
authorChris Burgess <chris@giantrobot.co.nz>
Mon, 11 Apr 2016 09:07:02 +0000 (21:07 +1200)
committerChris Burgess <chris@giantrobot.co.nz>
Mon, 11 Apr 2016 09:07:02 +0000 (21:07 +1200)
CRM/Core/BAO/CustomGroup.php

index c8d2e8d60045037ca3949a8632f0b2efc88efce9..e4caa8a689c51fffa7c0cbfb0ec4ef5ecdb2ee02 100644 (file)
@@ -441,10 +441,14 @@ LEFT JOIN civicrm_custom_field ON (civicrm_custom_field.custom_group_id = civicr
         $subTypeParts = explode(',', $subType);
         $subTypeClauses = array();
         foreach ($subTypeParts as $subTypePart) {
-          $subTypePart = CRM_Core_DAO::VALUE_SEPARATOR .
-            trim($subTypePart, CRM_Core_DAO::VALUE_SEPARATOR) .
-            CRM_Core_DAO::VALUE_SEPARATOR;
-          $subTypeClauses[] = "civicrm_custom_group.extends_entity_column_value LIKE '%$subTypePart%'";
+          // CRM-17984: Only filter by this input if valid.
+          $subTypePart = CRM_Utils_Type::escape(trim($subTypePart, CRM_Core_DAO::VALUE_SEPARATOR), 'Integer', FALSE);
+          if ($subTypePart) {
+            $subTypePart = CRM_Core_DAO::VALUE_SEPARATOR .
+              $subTypePart .
+              CRM_Core_DAO::VALUE_SEPARATOR;
+            $subTypeClauses[] = "civicrm_custom_group.extends_entity_column_value LIKE '%$subTypePart%'";
+          }
         }
 
         if ($onlySubType) {
@@ -456,19 +460,27 @@ LEFT JOIN civicrm_custom_field ON (civicrm_custom_field.custom_group_id = civicr
         }
       }
       else {
-        $subType = CRM_Core_DAO::VALUE_SEPARATOR .
-          trim($subType, CRM_Core_DAO::VALUE_SEPARATOR) .
-          CRM_Core_DAO::VALUE_SEPARATOR;
+        // CRM-17984: Only filter by this input if valid.
+        $subType = CRM_Utils_Type::escape(trim($subType, CRM_Core_DAO::VALUE_SEPARATOR), 'Integer', FALSE);
+        if ($subType) {
+          $subType = CRM_Core_DAO::VALUE_SEPARATOR .
+            $subType .
+            CRM_Core_DAO::VALUE_SEPARATOR;
 
-        if ($onlySubType) {
-          $subTypeClause = "( civicrm_custom_group.extends_entity_column_value LIKE '%$subType%' )";
-        }
-        else {
-          $subTypeClause = "( civicrm_custom_group.extends_entity_column_value LIKE '%$subType%'
-    OR    civicrm_custom_group.extends_entity_column_value IS NULL )";
+          if ($onlySubType) {
+            $subTypeClause = "( civicrm_custom_group.extends_entity_column_value LIKE '%$subType%' )";
+          }
+          else {
+            $subTypeClause = "( civicrm_custom_group.extends_entity_column_value LIKE '%$subType%'
+      OR    civicrm_custom_group.extends_entity_column_value IS NULL )";
+          }
         }
       }
 
+      if (empty($subTypeClause)) {
+        $subTypeClause = '1=1';
+      }
+
       $strWhere = "
 WHERE civicrm_custom_group.is_active = 1
   AND civicrm_custom_field.is_active = 1