Check file descriptor 60/201960/1
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 21 Mar 2019 08:05:10 +0000 (17:05 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 21 Mar 2019 08:05:10 +0000 (17:05 +0900)
Change-Id: Ib85fc88e9ea048db18ab2992f3c528ebdfc6ad3d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/port-internal.cc

index daa11ce9932c1b01c5a359db3a65f6b5bb65a6bd..264fa16715b8effb59d3ef42db50ae4c27ae402b 100644 (file)
@@ -68,6 +68,11 @@ int Port::Read(void* buf, unsigned int size) {
   int max_timeout = MAX_CNT * MAX_SLEEP; /* 10 sec */
   std::lock_guard<std::recursive_mutex> lock(mutex_);
 
+  if (fd_ < 0 || fd_ >= sysconf(_SC_OPEN_MAX)) {
+    LOGE("Invalid fd(%d)", fd_);
+    return RPC_PORT_ERROR_IO_ERROR;
+  }
+
   while (left) {
     nb = read(fd_, buffer, left);
     if (nb == 0) {
@@ -114,6 +119,11 @@ int Port::Write(const void* buf, unsigned int size) {
   struct timespec end_time = { 0, };
   std::lock_guard<std::recursive_mutex> lock(mutex_);
 
+  if (fd_ < 0 || fd_ >= sysconf(_SC_OPEN_MAX)) {
+    LOGE("Invalid fd(%d)", fd_);
+    return RPC_PORT_ERROR_IO_ERROR;
+  }
+
   fds[0].fd = fd_;
   fds[0].events = POLLOUT;
   fds[0].revents = 0;