Fixed possible NULL pointer dereference; thanks to Matthieu Bec. stable-1.5
authorFlorian Pose <fp@igh-essen.com>
Mon, 05 May 2014 13:49:45 +0200
branchstable-1.5
changeset 2541 1ddd186e9d2c
parent 2540 fca12d7035d1
child 2542 8dd49f6f6d32
Fixed possible NULL pointer dereference; thanks to Matthieu Bec.
master/master.c
--- a/master/master.c	Mon Mar 10 13:43:48 2014 +0100
+++ b/master/master.c	Mon May 05 13:49:45 2014 +0200
@@ -2651,6 +2651,7 @@
 {
     const ec_slave_t *slave;
     unsigned int i;
+    int ret = 0;
 
     if (down_interruptible(&master->master_sem)) {
         return -EINTR;
@@ -2658,6 +2659,11 @@
 
     slave = ec_master_find_slave_const(master, 0, slave_position);
 
+    if (slave == NULL) {
+       ret = -ENOENT;
+       goto out_get_slave;
+    }
+
     slave_info->position = slave->ring_position;
     slave_info->vendor_id = slave->sii.vendor_id;
     slave_info->product_code = slave->sii.product_code;
@@ -2694,9 +2700,10 @@
         slave_info->name[0] = 0;
     }
 
+out_get_slave:
     up(&master->master_sem);
 
-    return 0;
+    return ret;
 }
 
 /*****************************************************************************/