Skip to content
Snippets Groups Projects
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: default avatarRahix <rahix@rahix.de>
parent f189fff0
No related branches found
No related tags found
No related merge requests found
...@@ -119,18 +119,20 @@ static uint8_t UARTWriteCback( ...@@ -119,18 +119,20 @@ static uint8_t UARTWriteCback(
return ATT_SUCCESS; return ATT_SUCCESS;
} }
uint8_t ble_uart_tx_buf[129]; static uint8_t ble_uart_tx_buf[128];
uint8_t ble_uart_buf_tx_fill; static uint8_t ble_uart_buf_tx_fill;
int ble_uart_lasttick = 0; static int ble_uart_lasttick = 0;
void ble_uart_write(uint8_t *pValue, uint8_t len) void ble_uart_write(uint8_t *pValue, uint8_t len)
{ {
int i; for (int i = 0; i < len; i++) {
for (i = 0; i < len; i++) {
if (pValue[i] >= 0x20 && pValue[i] < 0x7f) { if (pValue[i] >= 0x20 && pValue[i] < 0x7f) {
ble_uart_tx_buf[ble_uart_buf_tx_fill] = pValue[i]; ble_uart_tx_buf[ble_uart_buf_tx_fill] = pValue[i];
ble_uart_buf_tx_fill++; 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) { if (ble_uart_buf_tx_fill > 0) {
AttsSetAttr( AttsSetAttr(
UART_TX_HDL, UART_TX_HDL,
...@@ -141,16 +143,14 @@ void ble_uart_write(uint8_t *pValue, uint8_t len) ...@@ -141,16 +143,14 @@ void ble_uart_write(uint8_t *pValue, uint8_t len)
int x = xTaskGetTickCount() - int x = xTaskGetTickCount() -
ble_uart_lasttick; ble_uart_lasttick;
if (x < 100) { 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); 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( AttsHandleValueNtf(
active_connection, active_connection,
UART_TX_HDL, UART_TX_HDL,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment