]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
hostap: Silence compiler warnings about IFNAMSIZ buffers
authorJouni Malinen <j@w1.fi>
Tue, 1 Jan 2019 17:38:58 +0000 (19:38 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 1 Jan 2019 17:38:58 +0000 (19:38 +0200)
Report interface name truncation and reject such cases in Host AP driver
initialization of the AP interface.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/drivers/driver_hostap.c

index 597da335e4748206b179176e1ed573215abe8b02..3f33bb5fb441ac5b46d07a06944190043c0123e6 100644 (file)
@@ -231,7 +231,11 @@ static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
        }
 
         memset(&ifr, 0, sizeof(ifr));
-        snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
+       if (os_snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap",
+                       drv->iface) >= (int) sizeof(ifr.ifr_name)) {
+               wpa_printf(MSG_ERROR, "hostap: AP interface name truncated");
+               return -1;
+       }
         if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
                wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
                           strerror(errno));
@@ -348,7 +352,10 @@ static int hostap_set_iface_flags(void *priv, int dev_up)
        struct ifreq ifr;
        char ifname[IFNAMSIZ];
 
-       os_snprintf(ifname, IFNAMSIZ, "%sap", drv->iface);
+       if (os_snprintf(ifname, IFNAMSIZ, "%sap", drv->iface) >= IFNAMSIZ) {
+               wpa_printf(MSG_ERROR, "hostap: AP interface name truncated");
+               return -1;
+       }
        if (linux_set_iface_flags(drv->ioctl_sock, ifname, dev_up) < 0)
                return -1;