[PATCH 01/17] sandbox: net: Ensure host name is always a valid string

Simon Glass sjg at chromium.org
Sun May 9 00:00:05 CEST 2021


At present if ifname is exactly IFNAMSIZ characters then it will result
in an unterminated string. Fix this by using strlcpy() instead.

Reported-by: Coverity (CID: 316358)

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/net/sandbox-raw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/sandbox-raw.c b/drivers/net/sandbox-raw.c
index ce66ff781ff..99eb7a3bbff 100644
--- a/drivers/net/sandbox-raw.c
+++ b/drivers/net/sandbox-raw.c
@@ -161,7 +161,7 @@ static int sb_eth_raw_of_to_plat(struct udevice *dev)
 
 	ifname = dev_read_string(dev, "host-raw-interface");
 	if (ifname) {
-		strncpy(priv->host_ifname, ifname, IFNAMSIZ);
+		strlcpy(priv->host_ifname, ifname, IFNAMSIZ);
 		printf(": Using %s from DT\n", priv->host_ifname);
 	}
 	if (dev_read_u32(dev, "host-raw-interface-idx",
-- 
2.31.1.607.g51e8a6a459-goog



More information about the U-Boot mailing list