Commit ec611574 authored by Rahix's avatar Rahix Committed by schneider
Browse files

fix(ble-uart): Prevent buffer overflow



For messages with lines longer than 129 characters, ble_uart_write would
start overwriting adjacent memory.  This commit fixes this by starting a
new line once the buffer runs full.
Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent f189fff0
......@@ -119,18 +119,20 @@ static uint8_t UARTWriteCback(
return ATT_SUCCESS;
}
uint8_t ble_uart_tx_buf[129];
uint8_t ble_uart_buf_tx_fill;
int ble_uart_lasttick = 0;
static uint8_t ble_uart_tx_buf[128];
static uint8_t ble_uart_buf_tx_fill;
static int ble_uart_lasttick = 0;
void ble_uart_write(uint8_t *pValue, uint8_t len)
{
int i;
for (i = 0; i < len; i++) {
for (int i = 0; i < len; i++) {
if (pValue[i] >= 0x20 && pValue[i] < 0x7f) {
ble_uart_tx_buf[ble_uart_buf_tx_fill] = pValue[i];
ble_uart_buf_tx_fill++;
} else if (pValue[i] == '\r' || pValue[i] == '\n') {
}
if (ble_uart_buf_tx_fill == 128 || pValue[i] == '\r' ||
pValue[i] == '\n') {
if (ble_uart_buf_tx_fill > 0) {
AttsSetAttr(
UART_TX_HDL,
......@@ -141,16 +143,14 @@ void ble_uart_write(uint8_t *pValue, uint8_t len)
int x = xTaskGetTickCount() -
ble_uart_lasttick;
if (x < 100) {
// Ugly hack if we already send something recently.
// TODO: figure out how fast we can send or use indications
/*
* TODO: Ugly hack if we already
* send something recently.
* Figure out how fast we
* can send or use indications.
*/
vTaskDelay(100 - x);
}
//printf("notify: ");
//int j;
//for(j=0;j<ble_uart_buf_tx_fill;j++) {
// printf("%02x ", ble_uart_tx_buf[j]);
//}
//printf("\n");
AttsHandleValueNtf(
active_connection,
UART_TX_HDL,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment