diff options
author | Angela Stegmaier <angelabaker@ti.com> | 2016-04-14 16:01:48 -0500 |
---|---|---|
committer | Angela Stegmaier <angelabaker@ti.com> | 2016-04-20 13:45:44 -0500 |
commit | 84f2b39f64a31827962c065554c29b4f255c6974 (patch) | |
tree | 3006ae37c4cd6df3f0e6cd2830d18c4c9c0ebe1d | |
parent | dc6c5082f478225b7fbce4216173e6c5b36100b4 (diff) | |
download | ipc-84f2b39f64a31827962c065554c29b4f255c6974.tar.gz |
Linux: Fix Error Handling in TransportRpmsg_delete
TransportRpmsg_delete was not checking for a NULL handle
before de-referencing it, resulting in an application crash
if it was called with a NULL handle. A NULL handle was
being passed to TransportRpmsg_delete in the case where
TransportRpmsg_create socket connect call failed. In this
case, TransportRpmsg_create called TransportRpmsg_delete
with a NULL handle.
This patch adds a check for a NULL handle before de-referencing
the pointer in TransportRpmsg_delete, and also takes care
to cleanup the socket in TransportRpmsg_create in the failure
case where it cannot be cleaned by TransportRpmsg_delete.
Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
-rw-r--r-- | linux/src/transport/TransportRpmsg.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/linux/src/transport/TransportRpmsg.c b/linux/src/transport/TransportRpmsg.c index 960b922..7eb3356 100644 --- a/linux/src/transport/TransportRpmsg.c +++ b/linux/src/transport/TransportRpmsg.c @@ -199,6 +199,8 @@ TransportRpmsg_Handle TransportRpmsg_create(TransportRpmsg_Params *params) fprintf(stderr, "TransportRpmsg_create: connect failed: %d (%s) procId: %d\n", errno, strerror(errno), params->rprocId); + close(sock); + TransportRpmsg_module->sock[clusterId] = INVALIDSOCKET; goto done; } @@ -213,6 +215,8 @@ TransportRpmsg_Handle TransportRpmsg_create(TransportRpmsg_Params *params) if (obj == NULL) { status = Ipc_E_MEMORY; + close(sock); + TransportRpmsg_module->sock[clusterId] = INVALIDSOCKET; goto done; } @@ -251,6 +255,9 @@ Void TransportRpmsg_delete(TransportRpmsg_Handle *pHandle) UInt16 clusterId; int sock; + if (obj == NULL) { + goto done; + } clusterId = obj->rprocId - MultiProc_getBaseIdOfCluster(); @@ -272,6 +279,7 @@ Void TransportRpmsg_delete(TransportRpmsg_Handle *pHandle) obj = NULL; } +done: *pHandle = NULL; } |