From: Andrew Scull Date: Mon, 30 May 2022 10:00:01 +0000 (+0000) Subject: serial: sandbox: Fix buffer underflow in puts X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-favicon.png?a=commitdiff_plain;h=337b26e4688720560662246eb7703860b68bd6e2;p=u-boot.git serial: sandbox: Fix buffer underflow in puts Fix the buffer underflow that would occur if puts is called with length of zero. Fixes: efa51f2bd64 ("serial: sandbox: Implement puts") Cc: Sean Anderson Cc: Simon Glass Reviewed-by: Sean Anderson --- 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) {