浏览代码

net: Check network device driver name

If name is longer than allocated space NAMESIZE
mac address is rewritten which show error
message like:

Error message:
Warning: Xlltemac.87000000 MAC addresses don't match:
Address in SROM is         30:00:00:00:00:00
Address in environment is  00:0a:35:00:6a:04

NAMESIZE contains Driver name + zero terminated character.

Signed-off-by: Michal Simek <monstr@monstr.eu>
Michal Simek 13 年之前
父节点
当前提交
58c583b6c2
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      net/eth.c

+ 8 - 0
net/eth.c

@@ -224,6 +224,14 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 int eth_register(struct eth_device *dev)
 int eth_register(struct eth_device *dev)
 {
 {
 	struct eth_device *d;
 	struct eth_device *d;
+
+	size_t len = strlen(dev->name);
+	if (len >= NAMESIZE) {
+		printf("Network driver name is too long (%zu >= %zu): %s\n",
+						len, NAMESIZE, dev->name);
+		return -1;
+	}
+
 	if (!eth_devices) {
 	if (!eth_devices) {
 		eth_current = eth_devices = dev;
 		eth_current = eth_devices = dev;
 		eth_current_changed();
 		eth_current_changed();