Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ddab291 authored by Yun-Hao Chung's avatar Yun-Hao Chung Committed by Yun-hao Chung
Browse files

Floss: Handle EOF case in socket read

socket read returns 0 when it reaches EOF. Without handling it, the
packet might be interpreted wrongly since it could be uninitialized.

Bug: 357792559
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: manually
Flag: EXEMPT, Floss-only changes

Change-Id: I82025b7a0ab34d329e67e104c9cd313231dc553a
parent d67eb600
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -145,6 +145,9 @@ int waitHciDev(int hci_interface) {
      if (n < 0) {
        bluetooth::log::error("Error reading control channel: {}", strerror(errno));
        break;
      } else if (n == 0) { // unlikely to happen, just a safeguard.
        bluetooth::log::error("Error reading control channel: EOF");
        break;
      }

      if (ev.opcode == MGMT_EV_COMMAND_COMP) {
+4 −0
Original line number Diff line number Diff line
@@ -141,6 +141,10 @@ uint16_t Mgmt::get_vs_opcode(uint16_t vendor_specification) {
          log::error("Failed to read mgmt socket: {}", -errno);
          close(fd);
          return ret_opcode;
        } else if (ret == 0) { // unlikely to happen, just a safeguard.
          log::error("Failed to read mgmt socket: EOF");
          close(fd);
          return ret_opcode;
        }

        if (cc_ev.opcode == MGMT_EV_COMMAND_COMPLETE) {
+3 −0
Original line number Diff line number Diff line
@@ -200,6 +200,9 @@ int mgmt_get_codec_capabilities(int fd, uint16_t hci) {
        if (ret < 0) {
          log::debug("Failed to read mgmt socket: {}", -errno);
          return -errno;
        } else if (ret == 0) { // unlikely to happen, just a safeguard.
          log::debug("Failed to read mgmt socket: EOF");
          return -1;
        }

        if (ev.opcode == MGMT_EV_COMMAND_COMPLETE) {