hostap: Silence compiler warnings about IFNAMSIZ buffers

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>
This commit is contained in:
Jouni Malinen 2019-01-01 19:38:58 +02:00
parent 2ea1fce3d6
commit b2f1e5458b

View file

@ -231,7 +231,11 @@ static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
} }
memset(&ifr, 0, sizeof(ifr)); 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) { if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s", wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
strerror(errno)); strerror(errno));
@ -348,7 +352,10 @@ static int hostap_set_iface_flags(void *priv, int dev_up)
struct ifreq ifr; struct ifreq ifr;
char ifname[IFNAMSIZ]; 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) if (linux_set_iface_flags(drv->ioctl_sock, ifname, dev_up) < 0)
return -1; return -1;