Fix a bug about ReadParcelable Impl 41/262641/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 17 Aug 2021 02:06:23 +0000 (11:06 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 17 Aug 2021 07:01:28 +0000 (16:01 +0900)
In 32-bit machine, the long size is 4 bytes. When calling the
ReadInt64() with timespec.tv_nsec. the buffer overflow is occurred.

Change-Id: Id5bcb26891c63b893b20d50e7dab4c38dbaea14b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/parcel-header-internal.cc

index 12cf541..888b13a 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <atomic>
 #include <climits>
+#include <limits>
 
 #include "parcel-header-internal.hh"
 
@@ -34,8 +35,14 @@ void ParcelHeader::WriteToParcel(tizen_base::Parcel* parcel) const {
 
 void ParcelHeader::ReadFromParcel(tizen_base::Parcel* parcel) {
   parcel->ReadInt32(&seq_num_);
-  parcel->ReadInt64(reinterpret_cast<int64_t*>(&time_stamp_.tv_sec));
-  parcel->ReadInt64(reinterpret_cast<int64_t*>(&time_stamp_.tv_nsec));
+
+  int64_t tv_sec = 0;
+  parcel->ReadInt64(&tv_sec);
+  time_stamp_.tv_sec = tv_sec & std::numeric_limits<time_t>::max();
+
+  int64_t tv_nsec = 0;
+  parcel->ReadInt64(&tv_nsec);
+  time_stamp_.tv_nsec = tv_nsec & std::numeric_limits<long>::max();
 }
 
 void ParcelHeader::SetSeqNum(int seq_num) {