[OpenWrt-Devel] [PATCH netifd 16/16] device: Fix null pointer derefence if device is unset

Hans Dedecker dedeckeh at gmail.com
Mon Feb 1 04:56:30 EST 2016


Fix null pointer deference in device_claim if device is unset in device_user
struct. Typically this is observed when the parent device is removed
from (mac)vlan device config followed by a network reload

Signed-off-by: Hans Dedecker <dedeckeh at gmail.com>
---
 device.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/device.c b/device.c
index 3404fee..9344e1b 100644
--- a/device.c
+++ b/device.c
@@ -333,6 +333,9 @@ int device_claim(struct device_user *dep)
 	if (dep->claimed)
 		return 0;
 
+	if (!dev)
+		return -1;
+
 	dep->claimed = true;
 	D(DEVICE, "Claim %s %s, new active count: %d\n", dev->type->name, dev->ifname, dev->active + 1);
 	if (++dev->active != 1)
@@ -721,12 +724,16 @@ device_apply_config(struct device *dev, const struct device_type *type,
 			free(dev->config);
 			dev->config = config;
 			if (change == DEV_CONFIG_RESTART && dev->present) {
+				int ret = 0;
+
 				device_set_present(dev, false);
 				if (dev->active && !dev->external) {
-					dev->set_state(dev, false);
-					dev->set_state(dev, true);
+					ret = dev->set_state(dev, false);
+					if (!ret)
+						ret = dev->set_state(dev, true);
 				}
-				device_set_present(dev, true);
+				if (!ret)
+					device_set_present(dev, true);
 			}
 			break;
 		case DEV_CONFIG_NO_CHANGE:
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list