From: Benjamin Marzinski Date: Mon, 11 Jun 2012 21:32:35 +0000 (-0500) Subject: multipath: fix libudev bug in sysfs_get_tgt_nodename X-Git-Tag: upstream/0.5.0~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb0f7127ba90ab5e8e71fc534a0a16cdbe96a88f;p=platform%2Fupstream%2Fmultipath-tools.git 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. Signed-off-by: Benjamin Marzinski --- diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 25c7cda..96ed308 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -216,11 +216,13 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) 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 */ @@ -239,11 +241,13 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) 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;