Subject: Re: [PATCH 2.6] dev.c: clear SIOCGIFHWADDR buffer if !dev->addr_len

From: Matt Domsch <[email-masked]>
Date: Mon, 1 Nov 2004 14:45:33 -0600

On Tue, Nov 02, 2004 at 07:41:31AM +1100, Herbert Xu wrote:
> You don't need the min anymore since you've checked that dev->addr_len
> is not greater than sizeof ifr->ifr_hwaddr.sa_data.

Good catch.

Signed-off-by: Matt Domsch <[email-masked]>

-- 
Matt Domsch
Sr. Software Engineer, Lead Engineer
Dell Linux Solutions linux.dell.com & www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com

===== net/core/dev.c 1.169 vs edited =====
--- 1.169/net/core/dev.c	2004-10-26 11:09:33 -05:00
+++ edited/net/core/dev.c	2004-11-01 14:42:59 -06:00
@@ -2375,8 +2375,13 @@
 			return dev_set_mtu(dev, ifr->ifr_mtu);
 
 		case SIOCGIFHWADDR:
-			memcpy(ifr->ifr_hwaddr.sa_data, dev->dev_addr,
-			       min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
+			if (net_ratelimit())
+				printk(KERN_DEBUG "Warning: %s uses obsolete ioctl(SIOCGIFHWADDR), please convert it to rtnetlink(3,7)\n", current->comm);
+
+			if ((size_t) dev->addr_len > sizeof ifr->ifr_hwaddr.sa_data)
+				return -EOVERFLOW;
+			memset(ifr->ifr_hwaddr.sa_data, 0, sizeof ifr->ifr_hwaddr.sa_data);
+			memcpy(ifr->ifr_hwaddr.sa_data, dev->dev_addr, dev->addr_len);
 			ifr->ifr_hwaddr.sa_family = dev->type;
 			return 0;