* [PATCH] Check for mapname length
@ 2005-12-09 11:43 Hannes Reinecke
0 siblings, 0 replies; only message in thread
From: Hannes Reinecke @ 2005-12-09 11:43 UTC (permalink / raw)
To: christophe varoqui; +Cc: device-mapper development
[-- Attachment #1: Type: text/plain, Size: 356 bytes --]
Hi Christophe,
you asked for it:
This patch checks whether the mapname returned by dm_task_get_name is
not zero-sized. So NULL is returned always for an invalid mapname.
Cheers,
Hannes
--
Dr. Hannes Reinecke hare@suse.de
SuSE Linux Products GmbH S390 & zSeries
Maxfeldstraße 5 +49 911 74053 688
90409 Nürnberg http://www.suse.de
[-- Attachment #2: multipath-tools-mapname-length.patch --]
[-- Type: text/x-patch, Size: 1477 bytes --]
[devmapper] Check mapname length
dm_task_get_name might return a zero-length string, which also
seem to indicate an invalid mapname. Fix dm_mapname() to always
return NULL if either no mapname or an zero-length mapname
was returned.
Signed-off-by: Hannes Reinecke <hare@suse.de>
diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c
--- a/kpartx/devmapper.c
+++ b/kpartx/devmapper.c
@@ -123,7 +123,7 @@ const char *
dm_mapname(int major, int minor)
{
struct dm_task *dmt;
- const char *mapname;
+ const char *mapname = NULL, *map;
if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
return NULL;
@@ -135,7 +135,10 @@ dm_mapname(int major, int minor)
if (!dm_task_run(dmt))
goto out;
- mapname = strdup(dm_task_get_name(dmt));
+ map = dm_task_get_name(dmt);
+ if (map && strlen(map))
+ mapname = strdup(map);
+
out:
dm_task_destroy(dmt);
return mapname;
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -675,7 +675,7 @@ out:
char *
dm_mapname(int major, int minor)
{
- char * response;
+ char * response = NULL, *map;
struct dm_task *dmt;
int r;
int loop = MAX_WAIT * LOOPS_PER_SEC;
@@ -709,7 +709,10 @@ dm_mapname(int major, int minor)
goto bad;
}
- response = STRDUP((char *)dm_task_get_name(dmt));
+ map = dm_task_get_name(dmt);
+ if (map && strlen(map))
+ response = STRDUP((char *)dm_task_get_name(dmt));
+
dm_task_destroy(dmt);
return response;
bad:
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-12-09 11:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-09 11:43 [PATCH] Check for mapname length Hannes Reinecke
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.