1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cov: extra pointer validation

Add few more internal errors to enusure there is no use of NULL pointers
along the code path.
This commit is contained in:
Zdenek Kabelac 2024-04-09 11:35:23 +02:00
parent 8545621d39
commit 3ce83f923d
6 changed files with 33 additions and 4 deletions

View File

@ -757,6 +757,11 @@ uint32_t dm_task_get_read_ahead(const struct dm_task *dmt, uint32_t *read_ahead)
struct dm_deps *dm_task_get_deps(struct dm_task *dmt) struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
{ {
if (!dmt) {
log_error(INTERNAL_ERROR "Missing dm_task.");
return NULL;
}
return (struct dm_deps *) (((char *) dmt->dmi.v4) + return (struct dm_deps *) (((char *) dmt->dmi.v4) +
dmt->dmi.v4->data_start); dmt->dmi.v4->data_start);
} }

View File

@ -1453,9 +1453,14 @@ static void *_report_get_field_data(struct dm_report *rh,
const struct dm_report_field_type *fields = fp->implicit ? _implicit_report_fields const struct dm_report_field_type *fields = fp->implicit ? _implicit_report_fields
: rh->fields; : rh->fields;
char *ret = fp->type->data_fn(object); char *ret;
if (!ret) if (!object) {
log_error(INTERNAL_ERROR "_report_get_field_data: missing object.");
return NULL;
}
if (!(ret = fp->type->data_fn(object)))
return NULL; return NULL;
return (void *)(ret + fields[fp->field_num].offset); return (void *)(ret + fields[fp->field_num].offset);

View File

@ -3742,6 +3742,11 @@ uint32_t vg_bad_status_bits(const struct volume_group *vg, uint64_t status)
{ {
uint32_t failure = 0; uint32_t failure = 0;
if (!vg) {
log_error(INTERNAL_ERROR "Missing volume group.");
return FAILED_NOTFOUND;
}
if ((status & CLUSTERED) && !_access_vg_clustered(vg->cmd, vg)) if ((status & CLUSTERED) && !_access_vg_clustered(vg->cmd, vg))
/* Return because other flags are considered undefined. */ /* Return because other flags are considered undefined. */
return FAILED_CLUSTERED; return FAILED_CLUSTERED;

View File

@ -765,6 +765,11 @@ uint32_t dm_task_get_read_ahead(const struct dm_task *dmt, uint32_t *read_ahead)
struct dm_deps *dm_task_get_deps(struct dm_task *dmt) struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
{ {
if (!dmt) {
log_error(INTERNAL_ERROR "Missing dm_task.");
return NULL;
}
return (struct dm_deps *) (((char *) dmt->dmi.v4) + return (struct dm_deps *) (((char *) dmt->dmi.v4) +
dmt->dmi.v4->data_start); dmt->dmi.v4->data_start);
} }

View File

@ -1451,10 +1451,14 @@ static void *_report_get_field_data(struct dm_report *rh,
{ {
const struct dm_report_field_type *fields = fp->implicit ? _implicit_report_fields const struct dm_report_field_type *fields = fp->implicit ? _implicit_report_fields
: rh->fields; : rh->fields;
char *ret;
char *ret = fp->type->data_fn(object); if (!object) {
log_error(INTERNAL_ERROR "_report_get_field_data: missing object.");
return NULL;
}
if (!ret) if (!(ret = fp->type->data_fn(object)))
return NULL; return NULL;
return (void *)(ret + fields[fp->field_num].offset); return (void *)(ret + fields[fp->field_num].offset);

View File

@ -618,6 +618,11 @@ static int _report_all_in_pv(struct cmd_context *cmd, struct processing_handle *
{ {
int r = ECMD_FAILED; int r = ECMD_FAILED;
if (!pv) {
log_error(INTERNAL_ERROR "_report_all_in_pv: missing pv.");
return r;
}
switch (type) { switch (type) {
case PVS: case PVS:
r = _pvs_single(cmd, pv->vg, pv, handle); r = _pvs_single(cmd, pv->vg, pv, handle);