1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

lvconvert: fix handling args in combining snapshots

Fixes commit 286d39ee3c, which was correct except
for a reversed strstr.  Now uses strchr, and modifies
a copy of the name so the original argv is preserved.
This commit is contained in:
David Teigland 2017-02-24 14:17:58 -06:00
parent 74ba326007
commit 84cceaf9b9

View File

@ -3668,8 +3668,9 @@ static int _lvconvert_combine_split_snapshot_single(struct cmd_context *cmd,
int lvconvert_combine_split_snapshot_cmd(struct cmd_context *cmd, int argc, char **argv) int lvconvert_combine_split_snapshot_cmd(struct cmd_context *cmd, int argc, char **argv)
{ {
const char *vgname = NULL; const char *vgname = NULL;
const char *lvname1; const char *lvname1_orig;
const char *lvname2; const char *lvname2_orig;
const char *lvname1_split;
char *vglv; char *vglv;
int vglv_sz; int vglv_sz;
@ -3687,20 +3688,25 @@ int lvconvert_combine_split_snapshot_cmd(struct cmd_context *cmd, int argc, char
* This is the only instance in all commands. * This is the only instance in all commands.
*/ */
lvname1 = cmd->position_argv[0]; lvname1_orig = cmd->position_argv[0];
lvname2 = cmd->position_argv[1]; lvname2_orig = cmd->position_argv[1];
if (strstr("/", lvname1) && !strstr("/", lvname2) && !getenv("LVM_VG_NAME")) { if (strchr(lvname1_orig, '/') && !strchr(lvname2_orig, '/') && !getenv("LVM_VG_NAME")) {
if (!validate_lvname_param(cmd, &vgname, &lvname1)) if (!(lvname1_split = dm_pool_strdup(cmd->mem, lvname1_orig)))
return_ECMD_FAILED; return_ECMD_FAILED;
vglv_sz = strlen(vgname) + strlen(lvname2) + 2; if (!validate_lvname_param(cmd, &vgname, &lvname1_split))
return_ECMD_FAILED;
vglv_sz = strlen(vgname) + strlen(lvname2_orig) + 2;
if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) || if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) ||
dm_snprintf(vglv, vglv_sz, "%s/%s", vgname, lvname2) < 0) { dm_snprintf(vglv, vglv_sz, "%s/%s", vgname, lvname2_orig) < 0) {
log_error("vg/lv string alloc failed."); log_error("vg/lv string alloc failed.");
return_ECMD_FAILED; return_ECMD_FAILED;
} }
/* vglv is now vgname/lvname2 and replaces lvname2_orig */
cmd->position_argv[1] = vglv; cmd->position_argv[1] = vglv;
} }