OSDN Git Service

Check the return value when reading HCI type byte
authorPavlin Radoslavov <pavlin@google.com>
Thu, 20 Aug 2015 23:53:16 +0000 (16:53 -0700)
committerPavlin Radoslavov <pavlin@google.com>
Mon, 24 Aug 2015 01:13:45 +0000 (18:13 -0700)
Add missing return value check when reading the HCI type byte.
This check is needed as a safeguard. For example, function
event_uart_has_bytes() could be called (indirectly)
within the run_reactor() loop not only when there are bytes to read,
but also if there is an error (e.g., EPOLLHUP | EPOLLRDHUP | EPOLLERR).

Bug: 23105107
Change-Id: Ic3b6e4d656406949e384c8106b0c607f7c221759

hci/src/hci_hal_h4.c

index 836937d..4fc4274 100644 (file)
@@ -174,9 +174,12 @@ static void event_uart_has_bytes(eager_reader_t *reader, UNUSED_ATTR void *conte
     callbacks->data_ready(current_data_type);
   } else {
     uint8_t type_byte;
-    eager_reader_read(reader, &type_byte, 1, true);
+    if (eager_reader_read(reader, &type_byte, 1, true) == 0) {
+      LOG_ERROR("%s could not read HCI message type", __func__);
+      return;
+    }
     if (type_byte < DATA_TYPE_ACL || type_byte > DATA_TYPE_EVENT) {
-      LOG_ERROR("[h4] Unknown HCI message type. Dropping this byte 0x%x, min %x, max %x", type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT);
+      LOG_ERROR("%s Unknown HCI message type. Dropping this byte 0x%x, min %x, max %x", __func__, type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT);
       return;
     }