Add exception handler for parcel data 06/213106/2
authorJunghoon Park <jh9216.park@samsung.com>
Fri, 30 Aug 2019 08:17:38 +0000 (17:17 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Fri, 30 Aug 2019 08:35:10 +0000 (17:35 +0900)
Change-Id: I856cb4f34af9682c6ecb7e59a1c70ba3bb29d076
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
src/parcel-internal.cc

index 6ece0b9..3fce740 100644 (file)
@@ -101,9 +101,11 @@ const char* Parcel::ReadString() {
 
   if (l <= 0)
     return nullptr;
-  const char* str = reinterpret_cast<const char*>(&data_[reader_]);
-  if (static_cast<int>(strlen(str) + 1) != l)
+  if (reader_ + l > data_.size())
+      return nullptr;
+  if (data_[reader_ + l - 1] != 0)
     return nullptr;
+  const char* str = reinterpret_cast<const char*>(&data_[reader_]);
   reader_ += l;
 
   return str;
@@ -118,9 +120,11 @@ bundle* Parcel::ReadBundle() {
 
   if (l <= 0)
     return nullptr;
-  const bundle_raw* str = reinterpret_cast<const bundle_raw*>(&data_[reader_]);
-  if (static_cast<int>(strlen(reinterpret_cast<const char*>(str)) + 1) != l)
+  if (reader_ + l > data_.size())
+      return nullptr;
+  if (data_[reader_ + l - 1] != 0)
     return nullptr;
+  const bundle_raw* str = reinterpret_cast<const bundle_raw*>(&data_[reader_]);
   reader_ += l;
 
   bundle* b = bundle_decode(str, l - 1);