robusten code by checking variables before accessing
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 19 Dec 2014 12:18:44 +0000 (13:18 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 19 Dec 2014 12:59:08 +0000 (13:59 +0100)
Change-Id: I73b03fddfb221d55734d6f8fd6b43c7707e32b9a
Reviewed-on: http://gerrit.tine20.com/customers/1474
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Calendar/Backend/Sql.php
tine20/Calendar/Model/Rrule.php

index 6e50e02..eaa770f 100644 (file)
@@ -305,7 +305,14 @@ class Calendar_Backend_Sql extends Tinebase_Backend_Sql_Abstract
         );
         
         if ($grantsFilter instanceof Calendar_Model_GrantFilter) {
-            $requiredGrants = array_intersect($grantsFilter->getRequiredGrants(), $this->_recordBasedGrants);
+            $requiredGrants = $grantsFilter->getRequiredGrants();
+            if (is_array($requiredGrants)) {
+                $requiredGrants = array_intersect($requiredGrants, $this->_recordBasedGrants);
+            } else {
+                // TODO throw exception here?
+                if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
+                    . ' Required grants not set in grants filter: ' . print_r($grantsFilter->toArray(), true));
+            }
         }
         
         foreach ($events as $event) {
@@ -358,7 +365,7 @@ class Calendar_Backend_Sql extends Tinebase_Backend_Sql_Abstract
             }
             
             // check if one of the grants is set ...
-            if (isset($requiredGrants)) {
+            if (isset($requiredGrants) && is_array($requiredGrants)) {
                 foreach ($requiredGrants as $requiredGrant) {
                     if ($event->{$requiredGrant}) {
                         continue 2;
index 2fd8241..cee5446 100644 (file)
@@ -604,6 +604,12 @@ class Calendar_Model_Rrule extends Tinebase_Record_Abstract
         }
         
         $rangeDate = $_which > 0 ? $until : $from;
+        
+        if (! isset($freqMap[$rrule->freq])) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::ERR)) Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__
+                    . ' Invalid RRULE:' . print_r($rrule->toArray(), true));
+            throw new Calendar_Exception('Invalid freq in RRULE: ' . $rrule->freq);
+        }
         $rangeDate->add($interval, $freqMap[$rrule->freq]);
         $attempts = 0;