Use os_strlcpy instead of os_strncpy when copying ifname
authorJouni Malinen <j@w1.fi>
Sun, 8 Feb 2009 11:26:33 +0000 (13:26 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 8 Feb 2009 11:26:33 +0000 (13:26 +0200)
In theory, the ifname could be IFNAMSIZ characters long and there would
not be room for null termination.

src/wps/wps_upnp.c

index 84afa34..6d2de0e 100644 (file)
@@ -859,7 +859,7 @@ static int get_netif_info(const char *net_if, unsigned *ip_addr,
        if (sock < 0)
                goto fail;
 
-       os_strncpy(req.ifr_name, net_if, sizeof(req.ifr_name));
+       os_strlcpy(req.ifr_name, net_if, sizeof(req.ifr_name));
        if (ioctl(sock, SIOCGIFADDR, &req) < 0) {
                wpa_printf(MSG_ERROR, "WPS UPnP: SIOCGIFADDR failed: %d (%s)",
                           errno, strerror(errno));
@@ -870,7 +870,7 @@ static int get_netif_info(const char *net_if, unsigned *ip_addr,
        in_addr.s_addr = *ip_addr;
        os_snprintf(*ip_addr_text, 16, "%s", inet_ntoa(in_addr));
 
-       os_strncpy(req.ifr_name, net_if, sizeof(req.ifr_name));
+       os_strlcpy(req.ifr_name, net_if, sizeof(req.ifr_name));
        if (ioctl(sock, SIOCGIFHWADDR, &req) < 0) {
                wpa_printf(MSG_ERROR, "WPS UPnP: SIOCGIFHWADDR failed: "
                           "%d (%s)", errno, strerror(errno));