serial: sandbox: Fix buffer underflow in puts

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

Fixes: efa51f2bd6 ("serial: sandbox: Implement puts")
Cc: Sean Anderson <sean.anderson@seco.com>
Cc: Simon Glass <sjg@chromium.org>
Reviewed-by: Sean Anderson <sean.anderson@seco.com>
This commit is contained in:
Andrew Scull 2022-05-30 10:00:01 +00:00 committed by Tom Rini
parent 9121478ee6
commit 337b26e468

View File

@ -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) {