diff --git a/system/stack/eatt/eatt.h b/system/stack/eatt/eatt.h index a029395a6f813ea61ed662dfe774fd8227431160..ba1d47a627a92b9f6196ce6400d47354d5e8ece1 100644 --- a/system/stack/eatt/eatt.h +++ b/system/stack/eatt/eatt.h @@ -99,6 +99,7 @@ class EattChannel { void EattChannelSetTxMTU(uint16_t tx_mtu) { this->tx_mtu_ = std::min<uint16_t>(tx_mtu, EATT_MAX_TX_MTU); + this->tx_mtu_ = std::max<uint16_t>(this->tx_mtu_, EATT_MIN_MTU_MPS); } }; diff --git a/system/stack/gatt/gatt_sr.cc b/system/stack/gatt/gatt_sr.cc index ad8f254054052086d82820087fdd6053f36204fb..8fc378703c9a27608bfb4ffbcedf0d71527966be 100644 --- a/system/stack/gatt/gatt_sr.cc +++ b/system/stack/gatt/gatt_sr.cc @@ -149,6 +149,13 @@ static void build_read_multi_rsp(tGATT_SR_CMD* p_cmd, uint16_t mtu) { uint8_t* p; bool is_overflow = false; + // We need at least one extra byte for the opcode + if (mtu == 0) { + LOG(ERROR) << "Invalid MTU"; + p_cmd->status = GATT_ILLEGAL_PARAMETER; + return; + } + len = sizeof(BT_HDR) + L2CAP_MIN_OFFSET + mtu; BT_HDR* p_buf = (BT_HDR*)osi_calloc(len); p_buf->offset = L2CAP_MIN_OFFSET;