Fix a wrong conditional statement in oicgroup
authorJihun Ha <jihun.ha@samsung.com>
Mon, 4 Apr 2016 01:12:16 +0000 (10:12 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 5 Apr 2016 10:47:08 +0000 (10:47 +0000)
strlen(actionTypeStr) at line 790 was always 0, which is not what it meant
to be. After assign a proper string to actionTypeStr, then strlen() function
should be used.

Change-Id: I2ac7dd5750f54f59eb16e9469fc4dcec5259bcc9
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7553
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
(cherry picked from commit d7c32ded070bccb20868674705a521f82964990f)
Reviewed-on: https://gerrit.iotivity.org/gerrit/7563

resource/csdk/stack/src/oicgroup.c

index 4997686..383d66a 100755 (executable)
@@ -787,14 +787,23 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
     }
 
     actionTypeStr = (char *)malloc(1024);
-    if(actionTypeStr != NULL && remaining >= strlen(actionTypeStr) + strlen(ACTION_DELIMITER) + 1)
+    if(actionTypeStr != NULL)
     {
         sprintf(actionTypeStr, "%ld %u", actionset->timesteps, actionset->type);
-        strncat(temp, actionTypeStr, strlen(actionTypeStr));
-        remaining -= strlen(actionTypeStr);
-        free(actionTypeStr);
-        strncat(temp, ACTION_DELIMITER, strlen(ACTION_DELIMITER));
-        remaining -= strlen(ACTION_DELIMITER);
+        if(remaining >= strlen(actionTypeStr) + strlen(ACTION_DELIMITER) + 1)
+        {
+            strncat(temp, actionTypeStr, strlen(actionTypeStr));
+            remaining -= strlen(actionTypeStr);
+            strncat(temp, ACTION_DELIMITER, strlen(ACTION_DELIMITER));
+            remaining -= strlen(ACTION_DELIMITER);
+            free(actionTypeStr);
+        }
+        else
+        {
+            free(actionTypeStr);
+            res = OC_STACK_ERROR;
+            goto exit;
+        }
     }
     else
     {