mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-24 22:43:35 +00:00
test/gatt_client: avoid invalid memory access in mock implementation
This commit is contained in:
parent
f920256470
commit
f959ac69f5
@ -5,7 +5,7 @@ CC = g++
|
||||
BTSTACK_ROOT = ../..
|
||||
|
||||
CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null -I. -I../ -I${BTSTACK_ROOT}/src
|
||||
CFLAGS += -fprofile-arcs -ftest-coverage
|
||||
CFLAGS += -fprofile-arcs -ftest-coverage -fsanitize=address
|
||||
LDFLAGS += -lCppUTest -lCppUTestExt
|
||||
|
||||
VPATH += ${BTSTACK_ROOT}/src
|
||||
|
@ -11,12 +11,14 @@
|
||||
#include "ble/gatt_client.h"
|
||||
#include "ble/sm.h"
|
||||
|
||||
#define PREBUFFER_SIZE (HCI_INCOMING_PRE_BUFFER_SIZE + 8)
|
||||
|
||||
static btstack_packet_handler_t att_packet_handler;
|
||||
static void (*registered_hci_event_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL;
|
||||
|
||||
static btstack_linked_list_t connections;
|
||||
static const uint16_t max_mtu = 23;
|
||||
static uint8_t l2cap_stack_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 8 + max_mtu]; // pre buffer + HCI Header + L2CAP header
|
||||
static uint8_t l2cap_stack_buffer[PREBUFFER_SIZE + max_mtu]; // pre buffer + HCI Header + L2CAP header
|
||||
static uint16_t gatt_client_handle = 0x40;
|
||||
static hci_connection_t hci_connection;
|
||||
|
||||
@ -76,8 +78,7 @@ int l2cap_can_send_connectionless_packet_now(void){
|
||||
}
|
||||
|
||||
uint8_t *l2cap_get_outgoing_buffer(void){
|
||||
// printf("l2cap_get_outgoing_buffer\n");
|
||||
return (uint8_t *)&l2cap_stack_buffer; // 8 bytes
|
||||
return (uint8_t *)&l2cap_stack_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 8];
|
||||
}
|
||||
|
||||
uint16_t l2cap_max_mtu(void){
|
||||
@ -116,8 +117,9 @@ void l2cap_request_can_send_fix_channel_now_event(uint16_t handle, uint16_t chan
|
||||
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
|
||||
att_connection_t att_connection;
|
||||
att_init_connection(&att_connection);
|
||||
uint8_t response[max_mtu];
|
||||
uint16_t response_len = att_handle_request(&att_connection, l2cap_get_outgoing_buffer(), len, &response[0]);
|
||||
uint8_t response_buffer[PREBUFFER_SIZE + max_mtu];
|
||||
uint8_t * response = &response_buffer[PREBUFFER_SIZE];
|
||||
uint16_t response_len = att_handle_request(&att_connection, l2cap_get_outgoing_buffer(), len, response);
|
||||
if (response_len){
|
||||
att_packet_handler(ATT_DATA_PACKET, gatt_client_handle, &response[0], response_len);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user