• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 27504bcf89193d47d7632cde922a65e0c051be01 Mon Sep 17 00:00:00 2001
2From: Theodore Ts'o <tytso@mit.edu>
3Date: Tue, 9 Aug 2022 11:16:47 -0400
4Subject: libext2fs: fix potential integer overflow in bitmap accessors
5
6bmap->cluster_bits has a maximum value of 19, but Coverity doesn't
7know that.  To make it happy, and just in case there is a bug where
8somehow the cluster size does get set to an invalid value and the rest
9of the library doesn't check it, use 1ULL instead of 1 to avoid the
10integer overflow.
11
12Addresses-Coverity-Bug: 1500759
13Addresses-Coverity-Bug: 1500764
14Addresses-Coverity-Bug: 1500771
15Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16---
17 lib/ext2fs/gen_bitmap64.c | 6 +++---
18 1 file changed, 3 insertions(+), 3 deletions(-)
19
20diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
21index d9809084..c860c10e 100644
22--- a/lib/ext2fs/gen_bitmap64.c
23+++ b/lib/ext2fs/gen_bitmap64.c
24@@ -684,7 +684,7 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap gen_bmap,
25
26 	/* convert to clusters if necessary */
27 	block >>= bmap->cluster_bits;
28-	end += (1 << bmap->cluster_bits) - 1;
29+	end += (1ULL << bmap->cluster_bits) - 1;
30 	end >>= bmap->cluster_bits;
31 	num = end - block;
32
33@@ -725,7 +725,7 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap gen_bmap,
34
35 	/* convert to clusters if necessary */
36 	block >>= bmap->cluster_bits;
37-	end += (1 << bmap->cluster_bits) - 1;
38+	end += (1ULL << bmap->cluster_bits) - 1;
39 	end >>= bmap->cluster_bits;
40 	num = end - block;
41
42@@ -766,7 +766,7 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap gen_bmap,
43
44 	/* convert to clusters if necessary */
45 	block >>= bmap->cluster_bits;
46-	end += (1 << bmap->cluster_bits) - 1;
47+	end += (1ULL << bmap->cluster_bits) - 1;
48 	end >>= bmap->cluster_bits;
49 	num = end - block;
50
51--
52cgit
53
54