]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: serial: fix serial_post_probe()
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 29 Sep 2023 00:47:16 +0000 (02:47 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 9 Oct 2023 19:24:31 +0000 (15:24 -0400)
The size of the name of a udevice is not limited.

When setting the fixed sized name field of a stdio device we must ensure
that the target string is NUL terminated to avoid buffer overflows.

Fixes: 57d92753d4ca ("dm: Add a uclass for serial devices")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/serial/serial-uclass.c

index 5e2e7dfbcb315f490939933f32018e5c8428cbac..4a2da7a3317620ac92abc8e83d6c71a3b991fc25 100644 (file)
@@ -520,7 +520,7 @@ static int serial_post_probe(struct udevice *dev)
                return 0;
        memset(&sdev, '\0', sizeof(sdev));
 
-       strncpy(sdev.name, dev->name, sizeof(sdev.name));
+       strlcpy(sdev.name, dev->name, sizeof(sdev.name));
        sdev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_DM;
        sdev.priv = dev;
        sdev.putc = serial_stub_putc;