From 2b43c3b4a3bddfeb10130ce2a5ed0673275cf7e1 Mon Sep 17 00:00:00 2001 From: Andreas Anderberg Date: Tue, 6 Feb 2024 13:55:48 +0100 Subject: [PATCH] drivers: serial: emul: Make fifo_read() respect size uart_emul_fifo_read() didn't regard the size arg, hence if the RX ring buffer contained more data than the size of the input rx_data buffer size, this could result in buffer overflow. This becomes more obvious when configuring device tree property latch-buffer-size > 1. Signed-off-by: Andreas Anderberg --- drivers/serial/uart_emul.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/serial/uart_emul.c b/drivers/serial/uart_emul.c index 645c888e53..2dc0f8495f 100644 --- a/drivers/serial/uart_emul.c +++ b/drivers/serial/uart_emul.c @@ -172,6 +172,7 @@ static int uart_emul_fifo_read(const struct device *dev, uint8_t *rx_data, int s K_SPINLOCK(&data->rx_lock) { bytes_to_read = MIN(config->latch_buffer_size, ring_buf_size_get(data->rx_rb)); + bytes_to_read = MIN(bytes_to_read, size); ring_buf_get(data->rx_rb, rx_data, bytes_to_read); }