[PATCH 1/2] dm: serial: fix serial_post_probe()

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Fri Sep 29 02:47:16 CEST 2023


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 at canonical.com>
---
 drivers/serial/serial-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 5e2e7dfbcb..4a2da7a331 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -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;
-- 
2.40.1



More information about the U-Boot mailing list