Skip to content

Commit 53dfb27

Browse files
jimmodpgeorge
authored andcommitted
extmod/modbluetooth: Clamp MTU values to 32->UINT16_MAX.
1 parent 92464f1 commit 53dfb27

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

extmod/modbluetooth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,15 +842,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gattc_exchange_mtu_obj, bluetooth
842842
STATIC mp_obj_t bluetooth_ble_l2cap_listen(mp_obj_t self_in, mp_obj_t psm_in, mp_obj_t mtu_in) {
843843
(void)self_in;
844844
mp_int_t psm = mp_obj_get_int(psm_in);
845-
mp_int_t mtu = mp_obj_get_int(mtu_in);
845+
mp_int_t mtu = MAX(32, MIN(UINT16_MAX, mp_obj_get_int(mtu_in)));
846846
return bluetooth_handle_errno(mp_bluetooth_l2cap_listen(psm, mtu));
847847
}
848848
STATIC MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_l2cap_listen_obj, bluetooth_ble_l2cap_listen);
849849

850850
STATIC mp_obj_t bluetooth_ble_l2cap_connect(size_t n_args, const mp_obj_t *args) {
851851
mp_int_t conn_handle = mp_obj_get_int(args[1]);
852852
mp_int_t psm = mp_obj_get_int(args[2]);
853-
mp_int_t mtu = mp_obj_get_int(args[3]);
853+
mp_int_t mtu = MAX(32, MIN(UINT16_MAX, mp_obj_get_int(args[3])));
854854
return bluetooth_handle_errno(mp_bluetooth_l2cap_connect(conn_handle, psm, mtu));
855855
}
856856
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_connect_obj, 4, 4, bluetooth_ble_l2cap_connect);

0 commit comments

Comments
 (0)