mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cov: wrap pvck call
Resolve reported leak by renaming existing pckk() to pvck_mf() and wrapping pvck() over this. This function can easily free allocated buffer within the subfunction.
This commit is contained in:
parent
dae792baad
commit
a07bf7b90b
29
tools/pvck.c
29
tools/pvck.c
@ -3002,10 +3002,9 @@ out:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pvck(struct cmd_context *cmd, int argc, char **argv)
|
static int _pvck_mf(struct metadata_file *mf, struct cmd_context *cmd, int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct settings set;
|
struct settings set = { 0 };
|
||||||
struct metadata_file mf;
|
|
||||||
struct device *dev = NULL;
|
struct device *dev = NULL;
|
||||||
struct devicefile *def = NULL;
|
struct devicefile *def = NULL;
|
||||||
const char *dump, *repair;
|
const char *dump, *repair;
|
||||||
@ -3015,9 +3014,6 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(&set, 0, sizeof(set));
|
|
||||||
memset(&mf, 0, sizeof(mf));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* By default LVM skips the first sector (sector 0), and writes
|
* By default LVM skips the first sector (sector 0), and writes
|
||||||
* the label_header in the second sector (sector 1).
|
* the label_header in the second sector (sector 1).
|
||||||
@ -3073,10 +3069,10 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
return_ECMD_FAILED;
|
return_ECMD_FAILED;
|
||||||
|
|
||||||
if (arg_is_set(cmd, file_ARG) && (arg_is_set(cmd, repairtype_ARG) || arg_is_set(cmd, repair_ARG))) {
|
if (arg_is_set(cmd, file_ARG) && (arg_is_set(cmd, repairtype_ARG) || arg_is_set(cmd, repair_ARG))) {
|
||||||
if (!(mf.filename = arg_str_value(cmd, file_ARG, NULL)))
|
if (!(mf->filename = arg_str_value(cmd, file_ARG, NULL)))
|
||||||
return_ECMD_FAILED;
|
return_ECMD_FAILED;
|
||||||
|
|
||||||
if (!_read_metadata_file(cmd, &mf))
|
if (!_read_metadata_file(cmd, mf))
|
||||||
return_ECMD_FAILED;
|
return_ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3149,10 +3145,10 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
ret = _repair_label_header(cmd, repair, &set, labelsector, dev);
|
ret = _repair_label_header(cmd, repair, &set, labelsector, dev);
|
||||||
|
|
||||||
else if (!strcmp(repair, "pv_header"))
|
else if (!strcmp(repair, "pv_header"))
|
||||||
ret = _repair_pv_header(cmd, repair, &set, &mf, labelsector, dev);
|
ret = _repair_pv_header(cmd, repair, &set, mf, labelsector, dev);
|
||||||
|
|
||||||
else if (!strcmp(repair, "metadata"))
|
else if (!strcmp(repair, "metadata"))
|
||||||
ret = _repair_metadata(cmd, repair, &set, &mf, labelsector, dev);
|
ret = _repair_metadata(cmd, repair, &set, mf, labelsector, dev);
|
||||||
else
|
else
|
||||||
log_error("Unknown repair value.");
|
log_error("Unknown repair value.");
|
||||||
|
|
||||||
@ -3166,10 +3162,10 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
|
|
||||||
/* repair is a combination of repairtype pv_header+metadata */
|
/* repair is a combination of repairtype pv_header+metadata */
|
||||||
|
|
||||||
if (!_repair_pv_header(cmd, "pv_header", &set, &mf, labelsector, dev))
|
if (!_repair_pv_header(cmd, "pv_header", &set, mf, labelsector, dev))
|
||||||
return_ECMD_FAILED;
|
return_ECMD_FAILED;
|
||||||
|
|
||||||
if (!_repair_metadata(cmd, "metadata", &set, &mf, labelsector, dev))
|
if (!_repair_metadata(cmd, "metadata", &set, mf, labelsector, dev))
|
||||||
return_ECMD_FAILED;
|
return_ECMD_FAILED;
|
||||||
|
|
||||||
return ECMD_PROCESSED;
|
return ECMD_PROCESSED;
|
||||||
@ -3202,3 +3198,12 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
return_ECMD_FAILED;
|
return_ECMD_FAILED;
|
||||||
return ECMD_PROCESSED;
|
return ECMD_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pvck(struct cmd_context *cmd, int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct metadata_file mf = { 0 };
|
||||||
|
int ret = _pvck_mf(&mf, cmd, argc, argv);
|
||||||
|
|
||||||
|
free(mf.text_buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user