]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
serial: sandbox: Fix buffer underflow in puts
authorAndrew Scull <ascull@google.com>
Mon, 30 May 2022 10:00:01 +0000 (10:00 +0000)
committerTom Rini <trini@konsulko.com>
Thu, 23 Jun 2022 16:58:18 +0000 (12:58 -0400)
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@seco.com>
Cc: Simon Glass <sjg@chromium.org>
Reviewed-by: Sean Anderson <sean.anderson@seco.com>
drivers/serial/sandbox.c

index e726e19c46f7bd288968da8d58d91a77117786a6..13b54921c419be21cc07458287e4cc8d8a7579ac 100644 (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) {