diff --git a/dist/tools/ethos/ethos.c b/dist/tools/ethos/ethos.c index 626ffd6e88..bef70d6955 100644 --- a/dist/tools/ethos/ethos.c +++ b/dist/tools/ethos/ethos.c @@ -156,7 +156,7 @@ typedef struct { **************************************************************************/ int tun_alloc(char *dev, int flags) { - struct ifreq ifr; + struct ifreq ifr = { 0 }; int fd, err; if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) { @@ -164,12 +164,10 @@ int tun_alloc(char *dev, int flags) { return fd; } - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_flags = flags; if (*dev) { - strncpy(ifr.ifr_name, dev, IFNAMSIZ); + strncpy(ifr.ifr_name, dev, IFNAMSIZ - 1); } if( (err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0 ) { @@ -515,8 +513,8 @@ int main(int argc, char *argv[]) serial_option = argv[3]; } - char ifname[IFNAMSIZ]; - strncpy(ifname, argv[1], IFNAMSIZ); + char ifname[IFNAMSIZ] = { 0 }; + strncpy(ifname, argv[1], IFNAMSIZ - 1); int tap_fd = tun_alloc(ifname, IFF_TAP | IFF_NO_PI); if (tap_fd < 0) {