Add pointer validation logic for oicgroup.
authorHyunJun Kim <hyunjun2.kim@samsung.com>
Wed, 15 Apr 2015 05:19:29 +0000 (14:19 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 15 Apr 2015 10:20:40 +0000 (10:20 +0000)
All pointer did't check NULL.
So it can occur runtime error.

But now, we add pointer validation logic
and It will support stability.

Change-Id: I4bf6d90ef5aa47c904595c6378b77d04a9106a5e
Signed-off-by: HyunJun Kim <hyunjun2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/725
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/stack/src/oicgroup.c

index 45522ed..99c3a55 100755 (executable)
@@ -536,6 +536,7 @@ OCStackResult ExtractKeyValueFromRequest(char *request, char **key,
     char* iterToken, *iterTokenPtr;
 
     iterToken = (char *) strtok_r(pRequest, ":", &iterTokenPtr);
+    VARIFY_POINTER_NULL(iterToken, result, exit);
     length = strlen(iterToken) + 1;
 
     *key = (char *) OCMalloc(length);
@@ -545,6 +546,7 @@ OCStackResult ExtractKeyValueFromRequest(char *request, char **key,
     ((*key)[((length - 1) - 2)]) = '\0';
 
     iterToken = (char *) strtok_r(NULL, "}", &iterTokenPtr);
+    VARIFY_POINTER_NULL(iterToken, result, exit);
     length = strlen(iterToken) + 1;
 
     *value = (char *) OCMalloc(length);
@@ -725,6 +727,7 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
 {
     char temp[1024] = { 0 };
     int remaining = 1023;
+    OCStackResult res = OC_STACK_ERROR;
 
     OCAction *action = actionset->head;
 
@@ -737,7 +740,8 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
     }
     else
     {
-        return OC_STACK_ERROR;
+        res = OC_STACK_ERROR;
+        goto exit;
     }
 
     while (action != NULL)
@@ -775,9 +779,15 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
     }
 
     *desc = (char *) OCMalloc(1024 - remaining);
+    VARIFY_POINTER_NULL(*desc, res, exit);
     strcpy(*desc, temp);
 
     return OC_STACK_OK;
+
+exit:
+    OCFREE(*desc);
+    return res;
+
 }
 
 OCStackApplicationResult ActionSetCB(void* context, OCDoHandle handle,
@@ -796,6 +806,9 @@ OCStackApplicationResult ActionSetCB(void* context, OCDoHandle handle,
                 (unsigned int) (strlen((char *) clientResponse->resJSONPayload)
                         + 1));
 
+        if( responseJson == NULL )
+            return OC_STACK_DELETE_TRANSACTION;
+
         // We need the body of response.
         // Copy the body from the response
         strcpy((char *) responseJson,
@@ -916,6 +929,10 @@ OCStackResult DoAction(OCResource* resource, OCActionSet* actionset,
 
         ClientRequestInfo *info = (ClientRequestInfo *) OCMalloc(
                 sizeof(ClientRequestInfo));
+
+        if( info == NULL )
+            return OC_STACK_NO_MEMORY;
+
         memset(info, 0, sizeof(ClientRequestInfo));
 
         info->collResource = resource;