]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
serial: smh: Check return value of strndup
authorSean Anderson <sean.anderson@seco.com>
Fri, 22 Apr 2022 18:50:23 +0000 (14:50 -0400)
committerTom Rini <trini@konsulko.com>
Thu, 5 May 2022 19:06:02 +0000 (15:06 -0400)
strndup can fail. Check for it.

Fixes: 4855b39be ("serial: smh: Implement puts for DM")
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
drivers/serial/serial_semihosting.c

index 4328b3dac5b7f9b2dfa64e5325f63f5f6739bea6..2561414e40f8f866d7328c46f3b5a34327afa934 100644 (file)
@@ -54,6 +54,9 @@ static ssize_t smh_serial_puts(struct udevice *dev, const char *s, size_t len)
                }
 
                buf = strndup(s, len);
+               if (!buf)
+                       return -ENOMEM;
+
                smh_puts(buf);
                free(buf);
                return len;