X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=blobdiff_plain;f=src%2Flinux%2Fdevice.c;h=b4360a6a88e39220417eec816948a8cbbdc3d9a7;hp=d418aaf6928f433497f81a9189b81fbef0de1823;hb=e913f3f232e4809b7218d081ab9f94cef1c94ac3;hpb=8d64561dbc0542e7e1185591b8ecde3e56e1bfca diff --git a/src/linux/device.c b/src/linux/device.c index d418aaf..b4360a6 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -107,17 +107,21 @@ static bool setup_device(void) { ifr.ifr_flags |= IFF_ONE_QUEUE; #endif - if(iface) + if(iface) { strncpy(ifr.ifr_name, iface, IFNAMSIZ); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + } if(!ioctl(device_fd, TUNSETIFF, &ifr)) { strncpy(ifrname, ifr.ifr_name, IFNAMSIZ); - if(iface) free(iface); + ifrname[IFNAMSIZ - 1] = 0; + free(iface); iface = xstrdup(ifrname); } else if(!ioctl(device_fd, (('T' << 8) | 202), &ifr)) { logger(LOG_WARNING, "Old ioctl() request was needed for %s", device); strncpy(ifrname, ifr.ifr_name, IFNAMSIZ); - if(iface) free(iface); + ifrname[IFNAMSIZ - 1] = 0; + free(iface); iface = xstrdup(ifrname); } else #endif @@ -126,8 +130,7 @@ static bool setup_device(void) { overwrite_mac = true; device_info = "Linux ethertap device"; device_type = DEVICE_TYPE_ETHERTAP; - if(iface) - free(iface); + free(iface); iface = xstrdup(strrchr(device, '/') ? strrchr(device, '/') + 1 : device); }