svn commit: trunk/busybox/networking: libiproute udhcp

vda at busybox.net vda at busybox.net
Mon Nov 27 23:44:57 UTC 2006


Author: vda
Date: 2006-11-27 15:44:57 -0800 (Mon, 27 Nov 2006)
New Revision: 16697

Log:
do not overflow ifr_name. maybe it was safe in some places,
but not everywhere. err to the safe side.


Modified:
   trunk/busybox/networking/ether-wake.c
   trunk/busybox/networking/interface.c
   trunk/busybox/networking/libiproute/ipaddress.c
   trunk/busybox/networking/libiproute/iplink.c
   trunk/busybox/networking/libiproute/iptunnel.c
   trunk/busybox/networking/route.c
   trunk/busybox/networking/udhcp/socket.c


Changeset:
Modified: trunk/busybox/networking/ether-wake.c
===================================================================
--- trunk/busybox/networking/ether-wake.c	2006-11-27 23:43:28 UTC (rev 16696)
+++ trunk/busybox/networking/ether-wake.c	2006-11-27 23:44:57 UTC (rev 16697)
@@ -145,7 +145,7 @@
 	{
 		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)
 			bb_perror_msg_and_die("SIOCGIFHWADDR on %s failed", ifname);
 

Modified: trunk/busybox/networking/interface.c
===================================================================
--- trunk/busybox/networking/interface.c	2006-11-27 23:43:28 UTC (rev 16696)
+++ trunk/busybox/networking/interface.c	2006-11-27 23:44:57 UTC (rev 16697)
@@ -617,12 +617,12 @@
 	int fd;
 	char *ifname = ife->name;
 
-	strcpy(ifr.ifr_name, ifname);
+	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 	if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
 		return -1;
 	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)
 		memset(ife->hwaddr, 0, 32);
 	else
@@ -630,20 +630,20 @@
 
 	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)
 		ife->metric = 0;
 	else
 		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)
 		ife->mtu = 0;
 	else
 		ife->mtu = ifr.ifr_mtu;
 
 #ifdef SIOCGIFMAP
-	strcpy(ifr.ifr_name, ifname);
+	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 	if (ioctl(skfd, SIOCGIFMAP, &ifr) == 0)
 		ife->map = ifr.ifr_map;
 	else
@@ -651,7 +651,7 @@
 		memset(&ife->map, 0, sizeof(struct ifmap));
 
 #ifdef HAVE_TXQUEUELEN
-	strcpy(ifr.ifr_name, ifname);
+	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 	if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0)
 		ife->tx_queue_len = -1;	/* unknown value */
 	else
@@ -663,24 +663,24 @@
 	/* IPv4 address? */
 	fd = get_socket_for_af(AF_INET);
 	if (fd >= 0) {
-		strcpy(ifr.ifr_name, ifname);
+		strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 		ifr.ifr_addr.sa_family = AF_INET;
 		if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
 			ife->has_ip = 1;
 			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)
 				memset(&ife->dstaddr, 0, sizeof(struct sockaddr));
 			else
 				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)
 				memset(&ife->broadaddr, 0, sizeof(struct sockaddr));
 			else
 				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)
 				memset(&ife->netmask, 0, sizeof(struct sockaddr));
 			else

Modified: trunk/busybox/networking/libiproute/ipaddress.c
===================================================================
--- trunk/busybox/networking/libiproute/ipaddress.c	2006-11-27 23:43:28 UTC (rev 16696)
+++ trunk/busybox/networking/libiproute/ipaddress.c	2006-11-27 23:44:57 UTC (rev 16697)
@@ -86,7 +86,7 @@
 		return;
 
 	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) {
 		perror("SIOCGIFXQLEN");
 		close(s);

Modified: trunk/busybox/networking/libiproute/iplink.c
===================================================================
--- trunk/busybox/networking/libiproute/iplink.c	2006-11-27 23:43:28 UTC (rev 16696)
+++ trunk/busybox/networking/libiproute/iplink.c	2006-11-27 23:44:57 UTC (rev 16697)
@@ -61,7 +61,7 @@
 	int fd;
 	int err;
 
-	strcpy(ifr.ifr_name, dev);
+	strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
 	fd = get_ctl_fd();
 	if (fd < 0)
 		return -1;
@@ -88,8 +88,8 @@
 	int fd;
 	int err;
 
-	strcpy(ifr.ifr_name, dev);
-	strcpy(ifr.ifr_newname, newdev);
+	strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
+	strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname));
 	fd = get_ctl_fd();
 	if (fd < 0)
 		return -1;
@@ -113,7 +113,7 @@
 		return -1;
 
 	memset(&ifr, 0, sizeof(ifr));
-	strcpy(ifr.ifr_name, dev);
+	strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
 	ifr.ifr_qlen = qlen;
 	if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
 		perror("SIOCSIFXQLEN");
@@ -135,7 +135,7 @@
 		return -1;
 
 	memset(&ifr, 0, sizeof(ifr));
-	strcpy(ifr.ifr_name, dev);
+	strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
 	ifr.ifr_mtu = mtu;
 	if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
 		perror("SIOCSIFMTU");
@@ -161,7 +161,7 @@
 	}
 
 	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) {
 		perror("SIOCGIFINDEX");
 		close(s);
@@ -194,7 +194,7 @@
 	int alen;
 
 	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;
 	alen = ll_addr_a2n((unsigned char *)(ifr->ifr_hwaddr.sa_data), 14, lla);
 	if (alen < 0)

Modified: trunk/busybox/networking/libiproute/iptunnel.c
===================================================================
--- trunk/busybox/networking/libiproute/iptunnel.c	2006-11-27 23:43:28 UTC (rev 16696)
+++ trunk/busybox/networking/libiproute/iptunnel.c	2006-11-27 23:44:57 UTC (rev 16697)
@@ -42,7 +42,7 @@
 	struct ifreq ifr;
 	int fd;
 
-	strcpy(ifr.ifr_name, dev);
+	strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
 	fd = xsocket(AF_INET, SOCK_DGRAM, 0);
 	if (ioctl(fd, SIOCGIFINDEX, &ifr)) {
 		bb_perror_msg("ioctl");
@@ -57,7 +57,7 @@
 	struct ifreq ifr;
 	int fd;
 
-	strcpy(ifr.ifr_name, dev);
+	strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
 	fd = xsocket(AF_INET, SOCK_DGRAM, 0);
 	if (ioctl(fd, SIOCGIFHWADDR, &ifr)) {
 		bb_perror_msg("ioctl");
@@ -91,7 +91,7 @@
 	int fd;
 	int err;
 
-	strcpy(ifr.ifr_name, basedev);
+	strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
 	ifr.ifr_ifru.ifru_data = (void*)p;
 	fd = xsocket(AF_INET, SOCK_DGRAM, 0);
 	err = ioctl(fd, SIOCGETTUNNEL, &ifr);
@@ -109,9 +109,9 @@
 	int err;
 
 	if (cmd == SIOCCHGTUNNEL && p->name[0]) {
-		strcpy(ifr.ifr_name, p->name);
+		strncpy(ifr.ifr_name, p->name, sizeof(ifr.ifr_name));
 	} else {
-		strcpy(ifr.ifr_name, basedev);
+		strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
 	}
 	ifr.ifr_ifru.ifru_data = (void*)p;
 	fd = xsocket(AF_INET, SOCK_DGRAM, 0);
@@ -130,9 +130,9 @@
 	int err;
 
 	if (p->name[0]) {
-		strcpy(ifr.ifr_name, p->name);
+		strncpy(ifr.ifr_name, p->name, sizeof(ifr.ifr_name));
 	} else {
-		strcpy(ifr.ifr_name, basedev);
+		strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
 	}
 	ifr.ifr_ifru.ifru_data = (void*)p;
 	fd = xsocket(AF_INET, SOCK_DGRAM, 0);

Modified: trunk/busybox/networking/route.c
===================================================================
--- trunk/busybox/networking/route.c	2006-11-27 23:43:28 UTC (rev 16696)
+++ trunk/busybox/networking/route.c	2006-11-27 23:44:57 UTC (rev 16697)
@@ -422,7 +422,7 @@
 	if (devname) {
 		struct ifreq 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) {
 			bb_perror_msg_and_die("SIOGIFINDEX");

Modified: trunk/busybox/networking/udhcp/socket.c
===================================================================
--- trunk/busybox/networking/udhcp/socket.c	2006-11-27 23:43:28 UTC (rev 16696)
+++ trunk/busybox/networking/udhcp/socket.c	2006-11-27 23:44:57 UTC (rev 16697)
@@ -51,7 +51,7 @@
 	}
 
 	ifr.ifr_addr.sa_family = AF_INET;
-	strcpy(ifr.ifr_name, interface);
+	strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
 	if (addr) {
 		if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
 			bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");




More information about the busybox-cvs mailing list