[PATCH v3 01/13] serial: sandbox: Fix buffer underflow in puts

Andrew Scull ascull at google.com
Mon May 30 12:00:01 CEST 2022


Fix the buffer underflow that would occur if puts is called with length
of zero.

Fixes: efa51f2bd64 ("serial: sandbox: Implement puts")
Cc: Sean Anderson <sean.anderson at seco.com>
Cc: Simon Glass <sjg at chromium.org>
---
 drivers/serial/sandbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index e726e19c46..13b54921c4 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -114,7 +114,7 @@ static ssize_t sandbox_serial_puts(struct udevice *dev, const char *s,
 	struct sandbox_serial_priv *priv = dev_get_priv(dev);
 	ssize_t ret;
 
-	if (s[len - 1] == '\n')
+	if (len && s[len - 1] == '\n')
 		priv->start_of_line = true;
 
 	if (sandbox_serial_enabled) {
-- 
2.36.1.124.g0e6072fb45-goog



More information about the U-Boot mailing list