[dm-devel] [PATCH 34/78] Check for valid DM_DEVICE_INFO before proceeding

Hannes Reinecke hare at suse.de
Mon Mar 16 12:36:21 UTC 2015


Calling 'DM_DEVICE_INFO' might succeed but the returned context
might refer to an invalid device. So one needs to check the 'exists'
field to avoid this.

Signed-off-by: Hannes Reinecke <hare at suse.de>
---
 libmultipath/devmapper.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 5e68aeb..1901052 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -615,6 +615,9 @@ dm_get_opencount (const char * mapname)
 	if (!dm_task_get_info(dmt, &info))
 		goto out;
 
+	if (!info.exists)
+		goto out;
+
 	r = info.open_count;
 out:
 	dm_task_destroy(dmt);
@@ -640,6 +643,9 @@ dm_get_major (char * mapname)
 	if (!dm_task_get_info(dmt, &info))
 		goto out;
 
+	if (!info.exists)
+		goto out;
+
 	r = info.major;
 out:
 	dm_task_destroy(dmt);
@@ -665,6 +671,9 @@ dm_get_minor (char * mapname)
 	if (!dm_task_get_info(dmt, &info))
 		goto out;
 
+	if (!info.exists)
+		goto out;
+
 	r = info.minor;
 out:
 	dm_task_destroy(dmt);
-- 
1.8.4.5




More information about the dm-devel mailing list