Skip to contentSkip to conversation

multipath: fix libudev bug in sysfs_get_tgt_nodename

PATCH New Benjamin Marzinski 1 participant 1 message Jun 11, 2012 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 multipath: fix libudev bug in sysfs_get_tgt_nodename

In a recent patch, I introduced a bug into sysfs_get_tgt_nodename(). multipath must not unreference the target udevice before it copies the tgt_nodename to another location, otherwise the value pointer will be pointing at freed memory.

libmultipath/discovery.c +6 -2
Index: multipath-tools-120518/libmultipath/discovery.c
===================================================================
@@ -215,11 +215,13 @@ sysfs_get_tgt_nodename (struct path *pp,
 		const char *value;
 
 		value = udev_device_get_sysattr_value(tgtdev, "node_name");
-		udev_device_unref(tgtdev);
 		if (value) {
 			strncpy(node, value, NODE_NAME_SIZE);
+			udev_device_unref(tgtdev);
 			return 0;
 		}
+		else
+			udev_device_unref(tgtdev);
 	}
 
 	/* Check for iSCSI */
@@ -238,11 +240,13 @@ sysfs_get_tgt_nodename (struct path *pp,
 			const char *value;
 
 			value = udev_device_get_sysattr_value(tgtdev, "targetname");
-			udev_device_unref(tgtdev);
 			if (value) {
 				strncpy(node, value, NODE_NAME_SIZE);
+				udev_device_unref(tgtdev);
 				return 0;
 			}
+			else
+				udev_device_unref(tgtdev);
 		}
 	}
 	return 1;