libmultipath, kpartx: fix callers of dm_get_next_target()
PATCH 1/1 libmultipath, kpartx: fix callers of dm_get_next_target()
From: Martin Wilck <[email protected]>
dm_get_next_target() may return NULL for target_type and params in some situations. Follows the same idea as the previous patch "dm_get_map: fix segfault when can't found target" by Wu Guanghao.
Signed-off-by Martin Wilck <[email protected]>
--- kpartx/devmapper.c | 6 ++++-- libmultipath/devmapper.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
kpartx/devmapper.c +4 -2
@@ -412,8 +412,10 @@ dm_get_map(const char *mapname, char * outparams) goto out;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, ¶ms); +if (dm_get_next_target (dmt,NULL , &start, &length, + &target_type, ¶ms) !=NULL || !params) +/* more than one target or not found target */ + goto out;if (snprintf (outparams,PARAMS_SIZE ,"%s" , params) <=PARAMS_SIZE ) r =0 ;
libmultipath/devmapper.c +10 -0
@@ -1715,6 +1715,16 @@ int dm_reassign_table(const char *name, char *old, char *new) do { next = dm_get_next_target(dmt, next, &start, &length, &target, ¶ms); + if (!target || !params) { + /* + * We can't call dm_task_add_target() with + * invalid parameters. But simply dropping this + * target feels wrong, too. Abort and warn. + */ + condlog(1, "%s: invalid target found in map %s", + __func__, name); + goto out_reload; + } buff = strdup(params); if (!buff) { condlog(3, "%s: failed to replace target %s, "
Signature · 6 lines
2.36.1 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Quoted 7 lines · On Tue, May 31, 2022 at 12:24:45PM +0200, [email protected] wrote:
From: Martin Wilck <[email protected]>
dm_get_next_target()may return NULL fortarget_typeand params in some situations. Follows the same idea as the previous patch "dm_get_map: fix segfault when can't found target" by Wu Guanghao.Signed-off-by Martin Wilck <[email protected]>
Reviewed-by Benjamin Marzinski <[email protected]>
Quoted 45 lines
--- kpartx/devmapper.c | 6 ++++-- libmultipath/devmapper.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)kpartx/devmapper.c +4
-2@@ -412,8 +412,10 @@ dm_get_map(const char *mapname, char * outparams) goto out;/* Fetch 1st target */ -dm_get_next_target (dmt,NULL , &start, &length, - &target_type, ¶ms); +if (dm_get_next_target (dmt,NULL , &start, &length, + &target_type, ¶ms) !=NULL || !params) +/* more than one target or not found target */ + goto out;if (snprintf (outparams,PARAMS_SIZE ,"%s" , params) <=PARAMS_SIZE ) r =0 ;libmultipath/devmapper.c +10
-0@@ -1715,6 +1715,16 @@ int dm_reassign_table(const char *name, char *old, char *new) do { next = dm_get_next_target(dmt, next, &start, &length, &target, ¶ms); + if (!target || !params) { + /* + * We can't call dm_task_add_target() with + * invalid parameters. But simply dropping this + * target feels wrong, too. Abort and warn. + */ + condlog(1, "%s: invalid target found in map %s", + __func__, name); + goto out_reload; + } buff = strdup(params); if (!buff) { condlog(3, "%s: failed to replace target %s, "Signature · 1 line
2.36.1
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel