sandbox: net: Ensure host name is always a valid string
authorSimon Glass <sjg@chromium.org>
Fri, 14 May 2021 01:39:17 +0000 (19:39 -0600)
committerTom Rini <trini@konsulko.com>
Thu, 15 Jul 2021 22:42:05 +0000 (18:42 -0400)
At present if ifname is exactly IFNAMSIZ characters then it will result
in an unterminated string. Fix this by using strlcpy() instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 316358)
Acked-by: Ramon Fried <rfried.dev@gmail.com>
drivers/net/sandbox-raw.c

index ce66ff7..99eb7a3 100644 (file)
@@ -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",