do not overflow ifr_name. maybe it was safe in some places,
but not everywhere. err to the safe side.
This commit is contained in:
parent
e2d3ded354
commit
229b3d2072
@ -145,7 +145,7 @@ int ether_wake_main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
struct ifreq if_hwaddr;
|
struct ifreq if_hwaddr;
|
||||||
|
|
||||||
strcpy(if_hwaddr.ifr_name, ifname);
|
strncpy(if_hwaddr.ifr_name, ifname, sizeof(if_hwaddr.ifr_name));
|
||||||
if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0)
|
if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0)
|
||||||
bb_perror_msg_and_die("SIOCGIFHWADDR on %s failed", ifname);
|
bb_perror_msg_and_die("SIOCGIFHWADDR on %s failed", ifname);
|
||||||
|
|
||||||
|
@ -617,12 +617,12 @@ static int if_fetch(struct interface *ife)
|
|||||||
int fd;
|
int fd;
|
||||||
char *ifname = ife->name;
|
char *ifname = ife->name;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
|
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
ife->flags = ifr.ifr_flags;
|
ife->flags = ifr.ifr_flags;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
|
if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
|
||||||
memset(ife->hwaddr, 0, 32);
|
memset(ife->hwaddr, 0, 32);
|
||||||
else
|
else
|
||||||
@ -630,20 +630,20 @@ static int if_fetch(struct interface *ife)
|
|||||||
|
|
||||||
ife->type = ifr.ifr_hwaddr.sa_family;
|
ife->type = ifr.ifr_hwaddr.sa_family;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0)
|
if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0)
|
||||||
ife->metric = 0;
|
ife->metric = 0;
|
||||||
else
|
else
|
||||||
ife->metric = ifr.ifr_metric;
|
ife->metric = ifr.ifr_metric;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
|
if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0)
|
||||||
ife->mtu = 0;
|
ife->mtu = 0;
|
||||||
else
|
else
|
||||||
ife->mtu = ifr.ifr_mtu;
|
ife->mtu = ifr.ifr_mtu;
|
||||||
|
|
||||||
#ifdef SIOCGIFMAP
|
#ifdef SIOCGIFMAP
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(skfd, SIOCGIFMAP, &ifr) == 0)
|
if (ioctl(skfd, SIOCGIFMAP, &ifr) == 0)
|
||||||
ife->map = ifr.ifr_map;
|
ife->map = ifr.ifr_map;
|
||||||
else
|
else
|
||||||
@ -651,7 +651,7 @@ static int if_fetch(struct interface *ife)
|
|||||||
memset(&ife->map, 0, sizeof(struct ifmap));
|
memset(&ife->map, 0, sizeof(struct ifmap));
|
||||||
|
|
||||||
#ifdef HAVE_TXQUEUELEN
|
#ifdef HAVE_TXQUEUELEN
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
|
if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
|
||||||
ife->tx_queue_len = -1; /* unknown value */
|
ife->tx_queue_len = -1; /* unknown value */
|
||||||
else
|
else
|
||||||
@ -663,24 +663,24 @@ static int if_fetch(struct interface *ife)
|
|||||||
/* IPv4 address? */
|
/* IPv4 address? */
|
||||||
fd = get_socket_for_af(AF_INET);
|
fd = get_socket_for_af(AF_INET);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
ifr.ifr_addr.sa_family = AF_INET;
|
ifr.ifr_addr.sa_family = AF_INET;
|
||||||
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
|
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
|
||||||
ife->has_ip = 1;
|
ife->has_ip = 1;
|
||||||
ife->addr = ifr.ifr_addr;
|
ife->addr = ifr.ifr_addr;
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0)
|
if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0)
|
||||||
memset(&ife->dstaddr, 0, sizeof(struct sockaddr));
|
memset(&ife->dstaddr, 0, sizeof(struct sockaddr));
|
||||||
else
|
else
|
||||||
ife->dstaddr = ifr.ifr_dstaddr;
|
ife->dstaddr = ifr.ifr_dstaddr;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0)
|
if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0)
|
||||||
memset(&ife->broadaddr, 0, sizeof(struct sockaddr));
|
memset(&ife->broadaddr, 0, sizeof(struct sockaddr));
|
||||||
else
|
else
|
||||||
ife->broadaddr = ifr.ifr_broadaddr;
|
ife->broadaddr = ifr.ifr_broadaddr;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, ifname);
|
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0)
|
if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0)
|
||||||
memset(&ife->netmask, 0, sizeof(struct sockaddr));
|
memset(&ife->netmask, 0, sizeof(struct sockaddr));
|
||||||
else
|
else
|
||||||
|
@ -86,7 +86,7 @@ static void print_queuelen(char *name)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strcpy(ifr.ifr_name, name);
|
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
|
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
|
||||||
perror("SIOCGIFXQLEN");
|
perror("SIOCGIFXQLEN");
|
||||||
close(s);
|
close(s);
|
||||||
|
@ -61,7 +61,7 @@ static int do_chflags(char *dev, __u32 flags, __u32 mask)
|
|||||||
int fd;
|
int fd;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, dev);
|
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
|
||||||
fd = get_ctl_fd();
|
fd = get_ctl_fd();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -88,8 +88,8 @@ static int do_changename(char *dev, char *newdev)
|
|||||||
int fd;
|
int fd;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, dev);
|
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
|
||||||
strcpy(ifr.ifr_newname, newdev);
|
strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname));
|
||||||
fd = get_ctl_fd();
|
fd = get_ctl_fd();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -113,7 +113,7 @@ static int set_qlen(char *dev, int qlen)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strcpy(ifr.ifr_name, dev);
|
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
|
||||||
ifr.ifr_qlen = qlen;
|
ifr.ifr_qlen = qlen;
|
||||||
if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
|
if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
|
||||||
perror("SIOCSIFXQLEN");
|
perror("SIOCSIFXQLEN");
|
||||||
@ -135,7 +135,7 @@ static int set_mtu(char *dev, int mtu)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strcpy(ifr.ifr_name, dev);
|
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
|
||||||
ifr.ifr_mtu = mtu;
|
ifr.ifr_mtu = mtu;
|
||||||
if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
|
if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
|
||||||
perror("SIOCSIFMTU");
|
perror("SIOCSIFMTU");
|
||||||
@ -161,7 +161,7 @@ static int get_address(char *dev, int *htype)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strcpy(ifr.ifr_name, dev);
|
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
|
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
|
||||||
perror("SIOCGIFINDEX");
|
perror("SIOCGIFINDEX");
|
||||||
close(s);
|
close(s);
|
||||||
@ -194,7 +194,7 @@ static int parse_address(char *dev, int hatype, int halen, char *lla, struct ifr
|
|||||||
int alen;
|
int alen;
|
||||||
|
|
||||||
memset(ifr, 0, sizeof(*ifr));
|
memset(ifr, 0, sizeof(*ifr));
|
||||||
strcpy(ifr->ifr_name, dev);
|
strncpy(ifr->ifr_name, dev, sizeof(ifr->ifr_name));
|
||||||
ifr->ifr_hwaddr.sa_family = hatype;
|
ifr->ifr_hwaddr.sa_family = hatype;
|
||||||
alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), 14, lla);
|
alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), 14, lla);
|
||||||
if (alen < 0)
|
if (alen < 0)
|
||||||
|
@ -42,7 +42,7 @@ static int do_ioctl_get_ifindex(char *dev)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, dev);
|
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
|
||||||
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (ioctl(fd, SIOCGIFINDEX, &ifr)) {
|
if (ioctl(fd, SIOCGIFINDEX, &ifr)) {
|
||||||
bb_perror_msg("ioctl");
|
bb_perror_msg("ioctl");
|
||||||
@ -57,7 +57,7 @@ static int do_ioctl_get_iftype(char *dev)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, dev);
|
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
|
||||||
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (ioctl(fd, SIOCGIFHWADDR, &ifr)) {
|
if (ioctl(fd, SIOCGIFHWADDR, &ifr)) {
|
||||||
bb_perror_msg("ioctl");
|
bb_perror_msg("ioctl");
|
||||||
@ -91,7 +91,7 @@ static int do_get_ioctl(char *basedev, struct ip_tunnel_parm *p)
|
|||||||
int fd;
|
int fd;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, basedev);
|
strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
|
||||||
ifr.ifr_ifru.ifru_data = (void*)p;
|
ifr.ifr_ifru.ifru_data = (void*)p;
|
||||||
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
||||||
err = ioctl(fd, SIOCGETTUNNEL, &ifr);
|
err = ioctl(fd, SIOCGETTUNNEL, &ifr);
|
||||||
@ -109,9 +109,9 @@ static int do_add_ioctl(int cmd, char *basedev, struct ip_tunnel_parm *p)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (cmd == SIOCCHGTUNNEL && p->name[0]) {
|
if (cmd == SIOCCHGTUNNEL && p->name[0]) {
|
||||||
strcpy(ifr.ifr_name, p->name);
|
strncpy(ifr.ifr_name, p->name, sizeof(ifr.ifr_name));
|
||||||
} else {
|
} else {
|
||||||
strcpy(ifr.ifr_name, basedev);
|
strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
|
||||||
}
|
}
|
||||||
ifr.ifr_ifru.ifru_data = (void*)p;
|
ifr.ifr_ifru.ifru_data = (void*)p;
|
||||||
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
||||||
@ -130,9 +130,9 @@ static int do_del_ioctl(char *basedev, struct ip_tunnel_parm *p)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (p->name[0]) {
|
if (p->name[0]) {
|
||||||
strcpy(ifr.ifr_name, p->name);
|
strncpy(ifr.ifr_name, p->name, sizeof(ifr.ifr_name));
|
||||||
} else {
|
} else {
|
||||||
strcpy(ifr.ifr_name, basedev);
|
strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
|
||||||
}
|
}
|
||||||
ifr.ifr_ifru.ifru_data = (void*)p;
|
ifr.ifr_ifru.ifru_data = (void*)p;
|
||||||
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
fd = xsocket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
@ -422,7 +422,7 @@ static void INET6_setroute(int action, char **args)
|
|||||||
if (devname) {
|
if (devname) {
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strcpy(ifr.ifr_name, devname);
|
strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
|
||||||
|
|
||||||
if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) {
|
if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) {
|
||||||
bb_perror_msg_and_die("SIOGIFINDEX");
|
bb_perror_msg_and_die("SIOGIFINDEX");
|
||||||
|
@ -51,7 +51,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ifr.ifr_addr.sa_family = AF_INET;
|
ifr.ifr_addr.sa_family = AF_INET;
|
||||||
strcpy(ifr.ifr_name, interface);
|
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
|
||||||
if (addr) {
|
if (addr) {
|
||||||
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
|
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
|
||||||
bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
|
bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
|
||||||
|
Loading…
Reference in New Issue
Block a user