Fixing crash in OCFillRandomMem (#512) 41/208341/1
authorsamanway.dey@samsung.com <samanway.dey@samsung.com>
Thu, 23 May 2019 11:18:06 +0000 (16:48 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 24 Jun 2019 00:49:10 +0000 (09:49 +0900)
- In commit ca4adaec79350756d58b124af22bece9c3ad186d there was
  a bug which causes crash in IoTivity, fixed that

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/c5711fd40dfbcaa3e47a6ac06ab08efd84ca66f2
(cherry picked from ca4adaec79350756d58b124af22bece9c3ad186d)

Change-Id: I65d5e1ce3cd2a51ca9d0dd60b10158c9c97bbef7
Signed-off-by: Samanway Dey <samanway.dey@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/c_common/ocrandom/src/ocrandom.c

index 97fe7be..babf32b 100644 (file)
@@ -187,17 +187,18 @@ int8_t OCSeedRandom()
 
 void OCFillRandomMem(uint8_t * location, uint16_t len)
 {
+    int i, j, rand_idx;
+    i = len;
     if (!location)
     {
         return;
     }
-    for (; len--;)
+    for (; i--;)
     {
         *location++ = OCGetRandomByte();
     }
     uint8_t *temp = (char *) OICCalloc(len, sizeof(char));
     int *mask = (int *) OICCalloc(len, sizeof(int));
-    int i, j, rand_idx;
     for (i = 0; i < len; i++)
     {
         mask[i] = 0;