diff options
author | osdl.net!shemminger <osdl.net!shemminger> | 2004-09-01 17:15:45 +0000 |
---|---|---|
committer | osdl.net!shemminger <osdl.net!shemminger> | 2004-09-01 17:15:45 +0000 |
commit | 71058eb8ef128aa99666dc4e6664e7632e12a1b9 (patch) | |
tree | 76870e45425f7c0e40762091a44b344dd32a438e /ip | |
parent | 139a7898b69b26cc269545f8be667dfa08d04a64 (diff) |
Fix ip command to not crash when interface name is too long.
always use strncpy(.., IFNAMSIZ)
(Logical change 1.79)
Diffstat (limited to 'ip')
-rw-r--r-- | ip/iplink.c | 26 | ||||
-rw-r--r-- | ip/iptunnel.c | 25 |
2 files changed, 25 insertions, 26 deletions
diff --git a/ip/iplink.c b/ip/iplink.c index a4132fa5..520280ed 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -82,13 +82,13 @@ static int get_ctl_fd(void) return -1; } -static int do_chflags(char *dev, __u32 flags, __u32 mask) +static int do_chflags(const char *dev, __u32 flags, __u32 mask) { struct ifreq ifr; int fd; int err; - strcpy(ifr.ifr_name, dev); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); fd = get_ctl_fd(); if (fd < 0) return -1; @@ -109,14 +109,14 @@ static int do_chflags(char *dev, __u32 flags, __u32 mask) return err; } -static int do_changename(char *dev, char *newdev) +static int do_changename(const char *dev, const char *newdev) { struct ifreq ifr; int fd; int err; - strcpy(ifr.ifr_name, dev); - strcpy(ifr.ifr_newname, newdev); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + strncpy(ifr.ifr_newname, newdev, IFNAMSIZ); fd = get_ctl_fd(); if (fd < 0) return -1; @@ -130,7 +130,7 @@ static int do_changename(char *dev, char *newdev) return err; } -static int set_qlen(char *dev, int qlen) +static int set_qlen(const char *dev, int qlen) { struct ifreq ifr; int s; @@ -140,7 +140,7 @@ static int set_qlen(char *dev, int qlen) return -1; memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, dev); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); ifr.ifr_qlen = qlen; if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) { perror("SIOCSIFXQLEN"); @@ -152,7 +152,7 @@ static int set_qlen(char *dev, int qlen) return 0; } -static int set_mtu(char *dev, int mtu) +static int set_mtu(const char *dev, int mtu) { struct ifreq ifr; int s; @@ -162,7 +162,7 @@ static int set_mtu(char *dev, int mtu) return -1; memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, dev); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); ifr.ifr_mtu = mtu; if (ioctl(s, SIOCSIFMTU, &ifr) < 0) { perror("SIOCSIFMTU"); @@ -174,7 +174,7 @@ static int set_mtu(char *dev, int mtu) return 0; } -static int get_address(char *dev, int *htype) +static int get_address(const char *dev, int *htype) { struct ifreq ifr; struct sockaddr_ll me; @@ -188,7 +188,7 @@ static int get_address(char *dev, int *htype) } memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, dev); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { perror("SIOCGIFINDEX"); close(s); @@ -216,12 +216,12 @@ static int get_address(char *dev, int *htype) return me.sll_halen; } -static int parse_address(char *dev, int hatype, int halen, char *lla, struct ifreq *ifr) +static int parse_address(const char *dev, int hatype, int halen, char *lla, struct ifreq *ifr) { int alen; memset(ifr, 0, sizeof(*ifr)); - strcpy(ifr->ifr_name, dev); + strncpy(ifr->ifr_name, dev, IFNAMSIZ); ifr->ifr_hwaddr.sa_family = hatype; alen = ll_addr_a2n(ifr->ifr_hwaddr.sa_data, 14, lla); if (alen < 0) diff --git a/ip/iptunnel.c b/ip/iptunnel.c index 45b904bd..19971a44 100644 --- a/ip/iptunnel.c +++ b/ip/iptunnel.c @@ -52,13 +52,13 @@ static void usage(void) exit(-1); } -static int do_ioctl_get_ifindex(char *dev) +static int do_ioctl_get_ifindex(const char *dev) { struct ifreq ifr; int fd; int err; - strcpy(ifr.ifr_name, dev); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); fd = socket(AF_INET, SOCK_DGRAM, 0); err = ioctl(fd, SIOCGIFINDEX, &ifr); if (err) { @@ -69,13 +69,13 @@ static int do_ioctl_get_ifindex(char *dev) return ifr.ifr_ifindex; } -static int do_ioctl_get_iftype(char *dev) +static int do_ioctl_get_iftype(const char *dev) { struct ifreq ifr; int fd; int err; - strcpy(ifr.ifr_name, dev); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); fd = socket(AF_INET, SOCK_DGRAM, 0); err = ioctl(fd, SIOCGIFHWADDR, &ifr); if (err) { @@ -105,14 +105,13 @@ static char * do_ioctl_get_ifname(int idx) } - -static int do_get_ioctl(char *basedev, struct ip_tunnel_parm *p) +static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p) { struct ifreq ifr; int fd; int err; - strcpy(ifr.ifr_name, basedev); + strncpy(ifr.ifr_name, basedev, IFNAMSIZ); ifr.ifr_ifru.ifru_data = (void*)p; fd = socket(AF_INET, SOCK_DGRAM, 0); err = ioctl(fd, SIOCGETTUNNEL, &ifr); @@ -122,16 +121,16 @@ static int do_get_ioctl(char *basedev, struct ip_tunnel_parm *p) return err; } -static int do_add_ioctl(int cmd, char *basedev, struct ip_tunnel_parm *p) +static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p) { struct ifreq ifr; int fd; int err; if (cmd == SIOCCHGTUNNEL && p->name[0]) - strcpy(ifr.ifr_name, p->name); + strncpy(ifr.ifr_name, p->name, IFNAMSIZ); else - strcpy(ifr.ifr_name, basedev); + strncpy(ifr.ifr_name, basedev, IFNAMSIZ); ifr.ifr_ifru.ifru_data = (void*)p; fd = socket(AF_INET, SOCK_DGRAM, 0); err = ioctl(fd, cmd, &ifr); @@ -141,16 +140,16 @@ static int do_add_ioctl(int cmd, char *basedev, struct ip_tunnel_parm *p) return err; } -static int do_del_ioctl(char *basedev, struct ip_tunnel_parm *p) +static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p) { struct ifreq ifr; int fd; int err; if (p->name[0]) - strcpy(ifr.ifr_name, p->name); + strncpy(ifr.ifr_name, p->name, IFNAMSIZ); else - strcpy(ifr.ifr_name, basedev); + strncpy(ifr.ifr_name, basedev, IFNAMSIZ); ifr.ifr_ifru.ifru_data = (void*)p; fd = socket(AF_INET, SOCK_DGRAM, 0); err = ioctl(fd, SIOCDELTUNNEL, &ifr); |