1dc728923Sopenharmony_ciFrom b795c06d8a44f42cdffdf5aa9561ff8de20d78cc Mon Sep 17 00:00:00 2001
2dc728923Sopenharmony_ciFrom: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
3dc728923Sopenharmony_ciDate: Mon, 7 Nov 2022 17:50:50 +0530
4dc728923Sopenharmony_ciSubject: libext2fs: fix ext2fs_compare_generic_bmap logic
5dc728923Sopenharmony_ci
6dc728923Sopenharmony_ciCurrently this function was not correctly comparing against the right
7dc728923Sopenharmony_cilength of the bitmap. Also when we compare bitarray v/s rbtree bitmap
8dc728923Sopenharmony_cithe value returned by ext2fs_test_generic_bmap() could be different in
9dc728923Sopenharmony_cithese two implementations.  Hence only check against boolean value.
10dc728923Sopenharmony_ci
11dc728923Sopenharmony_ciSigned-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
12dc728923Sopenharmony_ciSigned-off-by: Theodore Ts'o <tytso@mit.edu>
13dc728923Sopenharmony_ci---
14dc728923Sopenharmony_ci lib/ext2fs/gen_bitmap64.c | 10 +++++++---
15dc728923Sopenharmony_ci 1 file changed, 7 insertions(+), 3 deletions(-)
16dc728923Sopenharmony_ci
17dc728923Sopenharmony_cidiff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
18dc728923Sopenharmony_ciindex c860c10e..f7710afd 100644
19dc728923Sopenharmony_ci--- a/lib/ext2fs/gen_bitmap64.c
20dc728923Sopenharmony_ci+++ b/lib/ext2fs/gen_bitmap64.c
21dc728923Sopenharmony_ci@@ -629,10 +629,14 @@ errcode_t ext2fs_compare_generic_bmap(errcode_t neq,
22dc728923Sopenharmony_ci 	    (bm1->end != bm2->end))
23dc728923Sopenharmony_ci 		return neq;
24dc728923Sopenharmony_ci 
25dc728923Sopenharmony_ci-	for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
26dc728923Sopenharmony_ci-		if (ext2fs_test_generic_bmap(gen_bm1, i) !=
27dc728923Sopenharmony_ci-		    ext2fs_test_generic_bmap(gen_bm2, i))
28dc728923Sopenharmony_ci+	for (i = bm1->start; i < bm1->end; i++) {
29dc728923Sopenharmony_ci+		int ret1, ret2;
30dc728923Sopenharmony_ci+		ret1 = !!ext2fs_test_generic_bmap(gen_bm1, i);
31dc728923Sopenharmony_ci+		ret2 = !!ext2fs_test_generic_bmap(gen_bm2, i);
32dc728923Sopenharmony_ci+		if (ret1 != ret2) {
33dc728923Sopenharmony_ci 			return neq;
34dc728923Sopenharmony_ci+		}
35dc728923Sopenharmony_ci+	}
36dc728923Sopenharmony_ci 
37dc728923Sopenharmony_ci 	return 0;
38dc728923Sopenharmony_ci }
39dc728923Sopenharmony_ci-- 
40dc728923Sopenharmony_cicgit 
41dc728923Sopenharmony_ci
42