From fb38426d289ab010d2083a394dca685eed13e7ff Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 24 Feb 2017 12:56:40 +0100 Subject: [PATCH] lvconvert: validate name before prompt Before prompting make sure name fits. --- tools/lvconvert.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 4e8dbc868..3d7259e4e 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -2718,6 +2718,16 @@ static int _lvconvert_to_pool(struct cmd_context *cmd, memcpy(&lockd_data_id, &lv->lvid.id[1], sizeof(struct id)); } + /* + * The internal LV names for pool data/meta LVs. + */ + + if ((dm_snprintf(meta_name, sizeof(meta_name), "%s%s", lv->name, to_cachepool ? "_cmeta" : "_tmeta") < 0) || + (dm_snprintf(data_name, sizeof(data_name), "%s%s", lv->name, to_cachepool ? "_cdata" : "_tdata") < 0)) { + log_error("Failed to create internal lv names, pool name is too long."); + return 0; + } + /* * If an existing LV is to be used as the metadata LV, * verify that it's in a usable state. These checks are @@ -2842,7 +2852,6 @@ static int _lvconvert_to_pool(struct cmd_context *cmd, log_verbose("Pool metadata extents %u chunk_size %u", meta_extents, chunk_size); - /* * Verify that user wants to use these LVs. */ @@ -2869,16 +2878,6 @@ static int _lvconvert_to_pool(struct cmd_context *cmd, return 0; } - /* - * The internal LV names for pool data/meta LVs. - */ - - if ((dm_snprintf(meta_name, sizeof(meta_name), "%s%s", lv->name, to_cachepool ? "_cmeta" : "_tmeta") < 0) || - (dm_snprintf(data_name, sizeof(data_name), "%s%s", lv->name, to_cachepool ? "_cdata" : "_tdata") < 0)) { - log_error("Failed to create internal lv names, pool name is too long."); - return 0; - } - /* * If a new metadata LV needs to be created, collect the settings for * the new LV and create it. -- 2.43.5