From e150931fc4eb9a1c8bfc77477c6f8d8d30060536 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 29 Jul 2024 16:53:28 +0200 Subject: [PATCH] cov: validate list emptiness Emit internal error for empty list. --- device_mapper/libdm-report.c | 2 ++ lib/metadata/lv_manip.c | 2 +- libdm/libdm-report.c | 2 ++ tools/lvconvert.c | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/device_mapper/libdm-report.c b/device_mapper/libdm-report.c index d6d485964..6301d7e21 100644 --- a/device_mapper/libdm-report.c +++ b/device_mapper/libdm-report.c @@ -4757,6 +4757,8 @@ static int _output_as_rows(struct dm_report *rh) dm_list_iterate_items(fp, &rh->field_props) { if (fp->flags & FLD_HIDDEN) { dm_list_iterate_items(row, &rh->rows) { + if (dm_list_empty(&row->fields)) + continue; field = dm_list_item(dm_list_first(&row->fields), struct dm_report_field); dm_list_del(&field->list); } diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 35263b802..6252c4469 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -1959,7 +1959,7 @@ static uint32_t _stripes_per_mimage(struct lv_segment *seg) if (seg_is_mirrored(seg) && seg->area_count && seg_type(seg, 0) == AREA_LV) { last_lvseg = dm_list_item(dm_list_last(&seg_lv(seg, 0)->segments), struct lv_segment); - if (seg_is_striped(last_lvseg)) + if (last_lvseg && seg_is_striped(last_lvseg)) return last_lvseg->area_count; } diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c index 95d5733a2..f3a2cfb11 100644 --- a/libdm/libdm-report.c +++ b/libdm/libdm-report.c @@ -4755,6 +4755,8 @@ static int _output_as_rows(struct dm_report *rh) dm_list_iterate_items(fp, &rh->field_props) { if (fp->flags & FLD_HIDDEN) { dm_list_iterate_items(row, &rh->rows) { + if (dm_list_empty(&row->fields)) + continue; field = dm_list_item(dm_list_first(&row->fields), struct dm_report_field); dm_list_del(&field->list); } diff --git a/tools/lvconvert.c b/tools/lvconvert.c index c575f823b..220f1a9c5 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -5792,6 +5792,11 @@ static int _lvconvert_detach_writecache_when_clean(struct cmd_context *cmd, int is_lockd; int ret = 0; + if (dm_list_empty(&lr->poll_idls)) { + log_error(INTERNAL_ERROR "Cannot detach writecache."); + return 0; + } + idl = dm_list_item(dm_list_first(&lr->poll_idls), struct convert_poll_id_list); id = idl->id; is_lockd = lvmcache_vg_is_lockd_type(cmd, id->vg_name, NULL);