fix: check context before use (where missing) 36/166736/2
authorKrzysztof Dynowski <k.dynowski@samsung.com>
Wed, 3 Jan 2018 10:50:25 +0000 (11:50 +0100)
committerKrzysztof Dynowski <k.dynowski@samsung.com>
Fri, 12 Jan 2018 08:53:24 +0000 (09:53 +0100)
Change-Id: I6494cffdfb77bda7cc191a0be76f350b79322568

TEECLib/src/teec_api.c

index e4cb0c294aa92065562e6355d3d3804427a92af8..132f4d9d3b078f7698efd34c0e1766746d392979 100644 (file)
@@ -739,7 +739,7 @@ TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context,
 
        // Check if the context is initialized
        if (!checkContext(context)) {
-               LOGE(TEEC_LIB, "Invalid context %p", context);
+               LOGE(TEEC_LIB, "Invalid context");
                return TEEC_ERROR_BAD_PARAMETERS;
        }
 
@@ -876,7 +876,7 @@ TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context,
 
        // Check if the Context is initialized
        if (!checkContext(context)) {
-               LOGE(TEEC_LIB, "context is not found");
+               LOGE(TEEC_LIB, "Invalid context");
                return TEEC_ERROR_BAD_PARAMETERS;
        }
 
@@ -1016,6 +1016,13 @@ void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMem)
                return;
        }
 
+       // Check if the Context is initialized
+       if (!checkContext(context)) {
+               LOGE(TEEC_LIB, "Invalid context");
+               return;
+       }
+
+
        // Check if the Context imp structure is valid
        context_imp = (TEEC_ContextImp *)context->imp;
 
@@ -1098,6 +1105,12 @@ TEEC_Result TEEC_OpenSession(TEEC_Context *context, TEEC_Session *session,
                return TEEC_ERROR_BAD_PARAMETERS;
        }
 
+       // Check if the context is initialized
+       if (!checkContext(context)) {
+               LOGE(TEEC_LIB, "Invalid context");
+               return TEEC_ERROR_BAD_PARAMETERS;
+       }
+
        // Check if the context imp is valid
        TEEC_ContextImp *context_imp = (TEEC_ContextImp *)context->imp;
 
@@ -1279,6 +1292,12 @@ void TEEC_CloseSession(TEEC_Session *session)
                return;
        }
 
+       // Check if the context is initialized
+       if (!checkContext(session_imp->context)) {
+               LOGE(TEEC_LIB, "Invalid context");
+               return;
+       }
+
        // Check if Context imp is valid
        TEEC_ContextImp *context_imp = (TEEC_ContextImp *)session_imp->context->imp;
 
@@ -1359,6 +1378,12 @@ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t commandID,
                return TEEC_ERROR_BAD_PARAMETERS;
        }
 
+       // Check if the context is initialized
+       if (!checkContext(session_imp->context)) {
+               LOGE(TEEC_LIB, "Invalid context");
+               return TEEC_ERROR_BAD_PARAMETERS;
+       }
+
        // Check if Context imp is valid
        TEEC_ContextImp *context_imp = (TEEC_ContextImp *)session_imp->context->imp;
 
@@ -1507,6 +1532,12 @@ void TEEC_RequestCancellation(TEEC_Operation *operation)
                return;
        }
 
+       // Check if the context is initialized
+       if (!checkContext(session_imp->context)) {
+               LOGE(TEEC_LIB, "Invalid context");
+               return;
+       }
+
        // Check if Context imp is valid
        TEEC_ContextImp *context_imp = (TEEC_ContextImp *)session_imp->context->imp;