You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I observe a crash using esp32-nimble v0.5.1 .
The scenario is as follows:
I successfully connect to the BLE device with BLEClient::connect(), followed by get_service() and get_characteristic()
I periodically call BLERemoteCharacteristic::write_value() to control the device.
then I power off the device.
At that point my app panics:
thread 'main' panicked at /home/czajnik/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp32-nimble-0.5.1/src/client/ble_writer.rs:20:19:
attempt to subtract with overflow
Just before the panic I can see it disconnected the device:
I (67205) esp32_nimble::client::ble_client: Disconnected: 520
Corresponding line:
let mtu = { esp_idf_sys::ble_att_mtu(self.conn_handle) - 3}asusize;
Obviously the subtraction underflows, because ble_att_mtu() returns 0 if connection is gone:
/**
* Retrieves the ATT MTU of the specified connection. If an MTU exchange for
* this connection has occurred, the MTU is the lower of the two peers'
* preferred values. Otherwise, the MTU is the default value of 23.
*
* @param conn_handle The handle of the connection to query.
*
* @return The specified connection's ATT MTU, or 0 if
* there is no such connection.
*/
uint16_t ble_att_mtu(uint16_t conn_handle);
I could check the connection state before calling write_value(), but there's probably a race condition here (toctou error).
I assumed that write_value() should handle such a situation gracefully.
Do I miss something important here (I'm both Rust and BLE noob)?
The text was updated successfully, but these errors were encountered:
I observe a crash using
esp32-nimble v0.5.1
.The scenario is as follows:
BLEClient::connect()
, followed byget_service()
andget_characteristic()
BLERemoteCharacteristic::write_value()
to control the device.At that point my app panics:
Just before the panic I can see it disconnected the device:
Corresponding line:
Obviously the subtraction underflows, because
ble_att_mtu()
returns 0 if connection is gone:I could check the connection state before calling
write_value()
, but there's probably a race condition here (toctou error).I assumed that
write_value()
should handle such a situation gracefully.Do I miss something important here (I'm both Rust and BLE noob)?
The text was updated successfully, but these errors were encountered: