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,8 +805,7 @@ int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
static int _insert_lvconvert_layer(struct cmd_context *cmd,
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
char *format, *layer_name;
|
||||
size_t len;
|
||||
char format[NAME_LEN], layer_name[NAME_LEN];
|
||||
int i;
|
||||
|
||||
/*
|
||||
@ -819,22 +818,19 @@ static int _insert_lvconvert_layer(struct cmd_context *cmd,
|
||||
* and take the number from it.
|
||||
*/
|
||||
|
||||
len = strlen(lv->name) + 32;
|
||||
if (!(format = alloca(len)) ||
|
||||
!(layer_name = alloca(len)) ||
|
||||
dm_snprintf(format, len, "%s_mimage_%%d", lv->name) < 0) {
|
||||
log_error("lvconvert: layer name allocation failed.");
|
||||
if (dm_snprintf(format, sizeof(format), "%s_mimage_%%d", lv->name) < 0) {
|
||||
log_error("lvconvert: layer name creation failed.");
|
||||
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) {
|
||||
log_error("lvconvert: layer name generation failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dm_snprintf(layer_name, len, MIRROR_SYNC_LAYER "_%d", i) < 0) {
|
||||
log_error("layer name allocation failed.");
|
||||
if (dm_snprintf(layer_name, sizeof(layer_name), MIRROR_SYNC_LAYER "_%d", i) < 0) {
|
||||
log_error("layer name creation failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user