From a98709aeaecb1dfbb01acb71b818f12f305383ed Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 29 Mar 2024 00:07:38 +0100 Subject: [PATCH] cov: validate count is bigger then 0 To avoid teoretical underflow... --- device_mapper/libdm-report.c | 5 +++-- libdm/libdm-report.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/device_mapper/libdm-report.c b/device_mapper/libdm-report.c index aabd03b14..2a0036035 100644 --- a/device_mapper/libdm-report.c +++ b/device_mapper/libdm-report.c @@ -4416,8 +4416,9 @@ static int _sort_rows(struct dm_report *rh) qsort(rows, count, sizeof(**rows), _row_compare); dm_list_init(&rh->rows); - while (count--) - dm_list_add_h(&rh->rows, &(*rows)[count]->list); + + while (count > 0) + dm_list_add_h(&rh->rows, &(*rows)[--count]->list); return 1; } diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c index c015a57fe..863463c84 100644 --- a/libdm/libdm-report.c +++ b/libdm/libdm-report.c @@ -4415,8 +4415,9 @@ static int _sort_rows(struct dm_report *rh) qsort(rows, count, sizeof(**rows), _row_compare); dm_list_init(&rh->rows); - while (count--) - dm_list_add_h(&rh->rows, &(*rows)[count]->list); + + while (count > 0) + dm_list_add_h(&rh->rows, &(*rows)[--count]->list); return 1; }