Fix the exception handling 91/155291/1
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 12 Oct 2017 23:46:16 +0000 (08:46 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 12 Oct 2017 23:46:16 +0000 (08:46 +0900)
- Uses strnlen() instead of strlen()

Change-Id: I6339d45ae0d903a7a3e59c537f304362b8e09316
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/keyval.c
src/keyval_array.c

index 8c7a42f..e3f906a 100755 (executable)
@@ -19,6 +19,7 @@
  * Implementation of keyval object
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 
 #include "keyval_type.h"
@@ -247,12 +248,13 @@ size_t keyval_decode(unsigned char *byte, keyval_t **kv, size_t byte_size)
        byte_size -= sz_keysize;
        p += sz_keysize;
        key = (char *)p;
-       if ((strlen(key) + 1) != keysize)
-               return 0;
 
        if (byte_size < keysize)
                return 0;
 
+       if (!key || (strnlen(key, keysize) + 1) != keysize)
+               return 0;
+
        byte_size -= keysize;
        p += keysize;
        size = *((size_t *)p);
index f9c32b1..e05f79c 100755 (executable)
@@ -19,6 +19,7 @@
  * Implementation of keyval_array object
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <string.h>
 
@@ -361,12 +362,13 @@ size_t keyval_array_decode(void *byte, keyval_array_t **kva, size_t byte_size)
        byte_size -= sz_keysize;
        p += sz_keysize;
        key = (char *)p;
-       if ((strlen(key) + 1) != keysize)
-               return 0;
 
        if (byte_size < keysize)
                return 0;
 
+       if (!key || (strnlen(key, keysize) + 1) != keysize)
+               return 0;
+
        byte_size -= keysize;
        p += keysize;
        len = *((unsigned int *)p);