Fix memory access error 17/21917/2
authorMats Wichmann <mats@linux.com>
Tue, 15 Aug 2017 14:44:26 +0000 (08:44 -0600)
committerRandeep Singh <randeep.s@samsung.com>
Thu, 7 Sep 2017 06:58:15 +0000 (06:58 +0000)
off-by-one in allocating memory for a string: was no space
for the null terminator since strlen() was used to compute size.

Change-Id: Ic7b836416f2a5319f2906be504fec09de29182dc
Signed-off-by: Mats Wichmann <mats@linux.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21917
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/tool/json2cbor.c

index c36c94e..9d56f03 100644 (file)
@@ -268,7 +268,7 @@ static OCStackResult ConvertJSONStringToCBORFile(const char *jsonStr, const char
         OIC_LOG(ERROR, TAG, "Unable to parse JSON string");
         goto exit;
     }
-    size = strlen(jsonStr);
+    size = strlen(jsonStr) + 1;
     size_t bufferSize = 0;
     buffer = (uint8_t *)OICMalloc(size);
     if (!buffer)