This patch adds proper error checking to the saTmrTimerReschedule call
in the saTmr service. Specifically,

* Check that timerAttibutes->type is valid.
* Prevent changing of periodic timer to single-event timer
  and vice versa.
* Check that initialExpirationTime is positive and is absolute time
  in the future.
* Check that timerPeriodDuration is positive.

These are all defined in the spec for the saTmr service.

When possible, we do error checks in the library to avoid unnecessary
calls into the exec. Other error checks must be done in the exec.

Index: services/tmr.c
===================================================================
--- services/tmr.c      (revision 1764)
+++ services/tmr.c      (working copy)
@@ -434,6 +434,7 @@
        struct res_lib_tmr_timerreschedule res_lib_tmr_timerreschedule;
        struct timer_instance *timer_instance = NULL;
        SaAisErrorT error = SA_AIS_OK;
+       SaTimeT current_time = 0;
 
        /* DEBUG */
        log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerReschedule { 
id=%u }\n",
@@ -447,10 +448,32 @@
                goto error_exit;
        }
 
+       current_time = (SaTimeT)(api->timer_time_get());
+
+       if (current_time > 
req_lib_tmr_timerreschedule->timer_attributes.initialExpirationTime) {
+               error = SA_AIS_ERR_INVALID_PARAM;
+               goto error_put;
+       }
+
+       if (timer_instance->timer_attributes.timerPeriodDuration != 0) {
+               if 
(req_lib_tmr_timerreschedule->timer_attributes.timerPeriodDuration <= 0) {
+                       error = SA_AIS_ERR_INVALID_PARAM;
+                       goto error_put;
+               }
+       }
+       else {
+               if 
(req_lib_tmr_timerreschedule->timer_attributes.timerPeriodDuration != 0) {
+                       error = SA_AIS_ERR_INVALID_PARAM;
+                       goto error_put;
+               }
+       }
+
        memcpy (&timer_instance->timer_attributes,
                &req_lib_tmr_timerreschedule->timer_attributes,
                sizeof (SaTmrTimerAttributesT));
 
+error_put:
+
        hdb_handle_put (&timer_hdb, (unsigned int)(timer_instance->timer_id));
 
 error_exit:
Index: lib/tmr.c
===================================================================
--- lib/tmr.c   (revision 1764)
+++ lib/tmr.c   (working copy)
@@ -413,10 +413,16 @@
        printf ("[DEBUG]: saTmrTimerReschedule { id=%u }\n",
                (unsigned int)(timerId));
 
-       if (timerAttributes == NULL) {
+       if ((timerAttributes == NULL) || (callTime == NULL)) {
                return (SA_AIS_ERR_INVALID_PARAM);
        }
 
+       if ((timerAttributes->type != SA_TIME_ABSOLUTE) &&
+           (timerAttributes->type != SA_TIME_DURATION))
+       {
+               return (SA_AIS_ERR_INVALID_PARAM);
+       }
+
        error = saHandleInstanceGet (&tmrHandleDatabase, tmrHandle, (void 
*)&tmrInstance);
        if (error != SA_AIS_OK) {
                return (error);
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to