mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(nimble): Fix vulnerabilities in NimBLE examples
This commit is contained in:
@@ -70,7 +70,10 @@ ble_prox_cent_on_write(uint16_t conn_handle,
|
||||
const struct peer_chr *chr;
|
||||
int rc;
|
||||
const struct peer *peer = peer_find(conn_handle);
|
||||
|
||||
if (peer == NULL) {
|
||||
MODLOG_DFLT(ERROR, "Error: peer not found for conn_handle=%d", conn_handle);
|
||||
return 0;
|
||||
}
|
||||
chr = peer_chr_find_uuid(peer,
|
||||
BLE_UUID16_DECLARE(BLE_SVC_TX_POWER_UUID16),
|
||||
BLE_UUID16_DECLARE(BLE_SVC_PROX_CHR_UUID16_TX_PWR_LVL));
|
||||
@@ -247,7 +250,7 @@ ext_ble_prox_cent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
|
||||
/* Conversion */
|
||||
for (int i=0; i<6; i++) {
|
||||
test_addr[i] = (uint8_t )peer_addr[i];
|
||||
test_addr[5 - i] = (uint8_t )peer_addr[i];
|
||||
}
|
||||
|
||||
if (memcmp(test_addr, disc->addr.val, sizeof(disc->addr.val)) != 0) {
|
||||
@@ -266,9 +269,15 @@ ext_ble_prox_cent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
}
|
||||
|
||||
/* Search if Proximity Sensor (Link loss) UUID is advertised */
|
||||
if (disc->data[offset] == 0x03 && disc->data[offset + 1] == 0x03) {
|
||||
if ( disc->data[offset + 2] == 0x18 && disc->data[offset + 3] == 0x03 ) {
|
||||
return 1;
|
||||
if (disc->data[offset + 1] == 0x03) {
|
||||
int uuid_offset = offset + 2;
|
||||
int uuid_end = offset + 1 + disc->data[offset]; // len includes type+data
|
||||
while (uuid_offset + 1 < uuid_end) {
|
||||
// BLE uses little-endian: 0x1803 is stored as 0x03 0x18
|
||||
if (disc->data[uuid_offset] == 0x03 && disc->data[uuid_offset + 1] == 0x18) {
|
||||
return 1;
|
||||
}
|
||||
uuid_offset += 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,7 +562,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
#else
|
||||
#if MYNEWT_VAL(BLE_GATTC)
|
||||
/*** Go for service discovery after encryption has been successfully enabled ***/
|
||||
rc = peer_disc_all(event->connect.conn_handle,
|
||||
rc = peer_disc_all(event->enc_change.conn_handle,
|
||||
ble_prox_cent_on_disc_complete, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
|
||||
@@ -572,7 +581,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
event->cache_assoc.status,
|
||||
(event->cache_assoc.cache_state == 0) ? "INVALID" : "LOADED");
|
||||
/* Perform service discovery */
|
||||
rc = peer_disc_all(event->connect.conn_handle,
|
||||
rc = peer_disc_all(event->cache_assoc.conn_handle,
|
||||
blecent_on_disc_complete, NULL);
|
||||
if(rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
|
||||
@@ -636,7 +645,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
void
|
||||
ble_prox_cent_path_loss_task(void *pvParameters)
|
||||
{
|
||||
int8_t rssi;
|
||||
int8_t rssi = 0;
|
||||
int rc;
|
||||
int path_loss;
|
||||
|
||||
@@ -685,7 +694,10 @@ ble_prox_cent_link_loss_task(void *pvParameters)
|
||||
while (1) {
|
||||
for (int i = 0; i <= MYNEWT_VAL(BLE_MAX_CONNECTIONS); i++) {
|
||||
if (disconn_peer[i].link_lost && disconn_peer[i].addr != NULL) {
|
||||
MODLOG_DFLT(INFO, "Link lost for device with conn_handle %d", i);
|
||||
MODLOG_DFLT(INFO, "Link lost for peer %02x:%02x:%02x:%02x:%02x:%02x, slot %d",
|
||||
disconn_peer[i].addr[5], disconn_peer[i].addr[4],
|
||||
disconn_peer[i].addr[3], disconn_peer[i].addr[2],
|
||||
disconn_peer[i].addr[1], disconn_peer[i].addr[0], i);
|
||||
}
|
||||
}
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
|
||||
Reference in New Issue
Block a user