From: Hwankyu Jhun Date: Thu, 12 Oct 2017 23:46:16 +0000 (+0900) Subject: Fix the exception handling X-Git-Tag: accepted/tizen/4.0/unified/20171017.211603~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26ca0e94787e1a6bc56bf8f25556e47fe09147e3;p=platform%2Fcore%2Fbase%2Fbundle.git Fix the exception handling - Uses strnlen() instead of strlen() Change-Id: I6339d45ae0d903a7a3e59c537f304362b8e09316 Signed-off-by: Hwankyu Jhun --- diff --git a/src/keyval.c b/src/keyval.c index 8c7a42f..e3f906a 100755 --- a/src/keyval.c +++ b/src/keyval.c @@ -19,6 +19,7 @@ * Implementation of keyval object */ +#define _GNU_SOURCE #include #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); diff --git a/src/keyval_array.c b/src/keyval_array.c index f9c32b1..e05f79c 100755 --- a/src/keyval_array.c +++ b/src/keyval_array.c @@ -19,6 +19,7 @@ * Implementation of keyval_array object */ +#define _GNU_SOURCE #include #include @@ -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);