Reject BLE values before all mandatory subscriptions

This commit is contained in:
evgeny committed 2026-10-29 22:21:12 +01:00
1 parent 4016e6b73c
commit fabf0c1663
2 files changed
+11 -1

No files matched your search

+4
View File
@@ -394,6 +394,10 @@ void ble_backend_opened(struct ble_transport* t, ble_link_id id, unsigned int mt
void ble_backend_received(struct ble_transport* t, ble_link_id id, enum ble_wire_channel wire, const uint8_t* data, size_t len) {
struct ble_connection* c = lookup(t, id);
if (!c) return;
if (!c->opened) {
DEBUG_WARN(CAT, "BLE value before mandatory subscriptions link=%llu channel=%d bytes=%zu", (unsigned long long)id, wire, len);
close_link(t, c, "value before subscriptions"); return;
}
if (!data || !len || len > c->capacity || (unsigned)wire >= BLE_WIRE_COUNT) {
DEBUG_WARN(CAT, "BLE invalid wire value link=%llu channel=%d bytes=%zu", (unsigned long long)id, wire, len);
close_link(t, c, "invalid wire value"); return;
+7 -1
View File
@@ -17,6 +17,7 @@ static unsigned int mtu = 23;
static int hold, drop, reject_peer, ready_count, writable_count;
static int hold_ack;
static unsigned ack_timeouts;
static unsigned closed_count;
static uint64_t data_wire_bytes[3];
static ble_link_id incoming_ids[3];
static void run(void* arg);
@@ -85,6 +86,7 @@ static void run(void* arg) {
static int validate(void* arg, ble_link_id id, uint64_t node) { (void)arg; (void)id; (void)node; return !reject_peer; }
static void connection(void* arg, ble_link_id id, uint64_t node, enum ble_state s, const char* reason) {
(void)arg; (void)id; (void)node; if (s == BLE_READY) ready_count++;
if (s == BLE_CLOSED) closed_count++;
if (s == BLE_CLOSED && !strcmp(reason, "ACK progress timeout")) ack_timeouts++;
}
static void writable(void* arg, ble_link_id id) { (void)arg; (void)id; writable_count++; }
@@ -156,7 +158,11 @@ static void exercise(unsigned int test_mtu) {
CHECK(!ble_backend_incoming(t[2], &denied));
CHECK(!ble_rx_get(t[2], incoming_ids[2]));
ble_set_incoming(t[2], 1);
CHECK(ble_backend_incoming(t[2], &denied));
ble_link_id early = ble_backend_incoming(t[2], &denied); CHECK(early);
uint8_t early_hello[19] = {0, 1, 1}; early_hello[10] = 1; early_hello[18] = 3;
unsigned before_closed = closed_count;
ble_backend_received(t[2], early, BLE_WIRE_DATA, early_hello, sizeof(early_hello));
CHECK(closed_count == before_closed + 1 && ready_count == 4);
for (int i = 0; i < 3; i++) ble_destroy(t[i]);
drain(ua); uasync_destroy(ua, 0);
}