From: Sean Anderson Date: Fri, 22 Apr 2022 18:50:23 +0000 (-0400) Subject: serial: smh: Check return value of strndup X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=bfae2744dd136198a97b480bc0cc1814663fe33b;p=u-boot.git serial: smh: Check return value of strndup strndup can fail. Check for it. Fixes: 4855b39be ("serial: smh: Implement puts for DM") Signed-off-by: Sean Anderson --- diff --git a/drivers/serial/serial_semihosting.c b/drivers/serial/serial_semihosting.c index 4328b3dac5..2561414e40 100644 --- a/drivers/serial/serial_semihosting.c +++ b/drivers/serial/serial_semihosting.c @@ -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;