Linux: GateMP: Fix Error Handling When defaultGate Not Found Due to Timeout
authorAngela Stegmaier <angelabaker@ti.com>
Wed, 7 Mar 2018 19:39:54 +0000 (13:39 -0600)
committerAngela Stegmaier <angelabaker@ti.com>
Tue, 20 Mar 2018 14:58:29 +0000 (09:58 -0500)
In a corner case where remote NameServer requests take too long and
time out, it is possible that remoteSystemGate may be de-referenced
in GateMP_start when it wasn't allocated during GateMP_attach.

This patch improves error checking in GateMP_start to avoid the potential
NULL pointer de-reference. Before trying to access the remoteSystemGates
pointer during GateMP_start, we should first make sure that the pointer is
valid. Also check to make sure that the gate number does not exceed the
number of allocated gates.

If the corner case has been hit where the GateMP_attach failed but GateMP_open
later passes during GateMP_start, GateMP_start will now return an error,
resulting in Ipc_start returning an error. The application can then call
Ipc_start again.

Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
linux/src/api/gates/GateMP.c

index 47c1377278e8c716bfbb6470f9efa4bb4ffb0240..e42d954bce90fbd7abe3080c17500785ed513649 100644 (file)
@@ -279,8 +279,9 @@ Int GateMP_start(Void)
     if (status < 0) {
         GateMP_stop();
     }
-
-    GateMP_module->isStarted = TRUE;
+    else {
+        GateMP_module->isStarted = TRUE;
+    }
 
     return status;
 }
@@ -446,7 +447,19 @@ Int GateMP_open(String name, GateMP_Handle *handle)
                 case GateMP_RemoteProtect_SYSTEM:
                 case GateMP_RemoteProtect_CUSTOM1:
                 case GateMP_RemoteProtect_CUSTOM2:
-                    obj = GateMP_module->remoteSystemGates[arg];
+                    if (GateMP_module->remoteSystemGates != NULL) {
+                        if ((Int)arg < GateMP_module->numRemoteSystem) {
+                            obj = GateMP_module->remoteSystemGates[arg];
+                        }
+                        else {
+                            status = GateMP_E_FAIL;
+                            PRINTVERBOSE1("GateMP_open: invalid system gate index [%d]\n", arg)
+                        }
+                    }
+                    else {
+                        status = GateMP_E_FAIL;
+                        PRINTVERBOSE0("GateMP_open: GateMP is not attached\n")
+                    }
                     break;
 
                 default: