]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blobdiff - packages/ti/sdo/ipc/Notify.c
Notify: Add NULL check for robustness
[ipc/ipcdev.git] / packages / ti / sdo / ipc / Notify.c
index 0bab916a2c84e324473435378e37db41bcfdd3a0..ebde75d35278c248160fb8cf64d14ed677a72d68 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2014, Texas Instruments Incorporated
+ * Copyright (c) 2012-2019, Texas Instruments Incorporated
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -123,10 +123,14 @@ Int Notify_attach(UInt16 remoteProcId, Ptr sharedAddr)
 {
     Int status;
 
-    Assert_isTrue(remoteProcId < ti_sdo_utils_MultiProc_numProcessors,
-        ti_sdo_ipc_Notify_A_invArgument);
+    /* validate remote processor ID */
+    if ((remoteProcId >= ti_sdo_utils_MultiProc_numProcessors)
+            || (remoteProcId == MultiProc_self())) {
 
-    /* Use the NotifySetup proxy to setup drivers */
+        return (Notify_E_INVALIDARG);
+    }
+
+    /* use the NotifySetup proxy to setup drivers */
     status = ti_sdo_ipc_Notify_SetupProxy_attach(remoteProcId, sharedAddr);
 
     return (status);
@@ -351,6 +355,11 @@ Int Notify_registerEvent(UInt16                 procId,
     listener->callback.cbckArg = cbckArg;
 
     eventList = List_Object_get(obj->eventList, strippedEventId);
+    if (eventList == NULL) {
+        Gate_leaveModule(modKey);
+
+        return (Notify_E_RESOURCE);
+    }
 
     /*
      *  Store whether the list was empty so we know whether to register the
@@ -641,6 +650,10 @@ Int Notify_unregisterEvent(UInt16                 procId,
 
     eventList = List_Object_get(obj->eventList, strippedEventId);
 
+    if ( eventList == NULL) {
+        return (Notify_E_NOTFOUND);
+    }
+
     if (List_empty(eventList)) {
         return (Notify_E_NOTFOUND);
     }
@@ -899,6 +912,13 @@ Void ti_sdo_ipc_Notify_execMany(UInt16 procId, UInt16 lineId, UInt32 eventId,
     /* Both loopback and the the event itself are enabled */
     eventList = List_Object_get(obj->eventList, eventId);
 
+    /* Check eventList Non Null */
+    Assert_isTrue(eventList != NULL, ti_sdo_ipc_Notify_A_internal);
+    /* Additional check to handle case when Assert is disabled */
+    if(eventList == NULL) {
+        return;
+    }
+
     /* Use "NULL" to get the first EventListener on the list */
     listener = (ti_sdo_ipc_Notify_EventListener *)List_next(eventList, NULL);
     while (listener != NULL) {