mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
cleanup: use NAME_LEN buffer instead of alloca
Drop alloca and use NAME_LEN size to get implicit check for max len of LV name.
This commit is contained in:
parent
2e04eee192
commit
5c48ef993b
@ -805,36 +805,32 @@ int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv,
|
|||||||
static int _insert_lvconvert_layer(struct cmd_context *cmd,
|
static int _insert_lvconvert_layer(struct cmd_context *cmd,
|
||||||
struct logical_volume *lv)
|
struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
char *format, *layer_name;
|
char format[NAME_LEN], layer_name[NAME_LEN];
|
||||||
size_t len;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We would like to give the same number for this layer
|
* We would like to give the same number for this layer
|
||||||
* and the newly added mimage.
|
* and the newly added mimage.
|
||||||
* However, LV name of newly added mimage is determined *after*
|
* However, LV name of newly added mimage is determined *after*
|
||||||
* the LV name of this layer is determined.
|
* the LV name of this layer is determined.
|
||||||
*
|
*
|
||||||
* So, use generate_lv_name() to generate mimage name first
|
* So, use generate_lv_name() to generate mimage name first
|
||||||
* and take the number from it.
|
* and take the number from it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
len = strlen(lv->name) + 32;
|
if (dm_snprintf(format, sizeof(format), "%s_mimage_%%d", lv->name) < 0) {
|
||||||
if (!(format = alloca(len)) ||
|
log_error("lvconvert: layer name creation failed.");
|
||||||
!(layer_name = alloca(len)) ||
|
|
||||||
dm_snprintf(format, len, "%s_mimage_%%d", lv->name) < 0) {
|
|
||||||
log_error("lvconvert: layer name allocation failed.");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!generate_lv_name(lv->vg, format, layer_name, len) ||
|
if (!generate_lv_name(lv->vg, format, layer_name, sizeof(layer_name)) ||
|
||||||
sscanf(layer_name, format, &i) != 1) {
|
sscanf(layer_name, format, &i) != 1) {
|
||||||
log_error("lvconvert: layer name generation failed.");
|
log_error("lvconvert: layer name generation failed.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dm_snprintf(layer_name, len, MIRROR_SYNC_LAYER "_%d", i) < 0) {
|
if (dm_snprintf(layer_name, sizeof(layer_name), MIRROR_SYNC_LAYER "_%d", i) < 0) {
|
||||||
log_error("layer name allocation failed.");
|
log_error("layer name creation failed.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user