diff options
author | Theodore Ts'o <tytso@mit.edu> | 2022-08-07 19:47:25 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2022-08-07 19:49:33 -0400 |
commit | 5cfdceb4909d9ee6ac2502b83215fb71f5077e06 (patch) | |
tree | 8da558bd1d2e42e3338f81ac000bab9ca9dee5f2 | |
parent | 80e1504f2ce33c9ebc5045009c7bcde9315526c0 (diff) | |
download | e2fsprogs-5cfdceb4909d9ee6ac2502b83215fb71f5077e06.tar.gz |
Fix UBSAN if s_log_groups_per_flex is 31
It is logal (albeit rare) for the number of block groups per flex_bg
to 2**31 (which effectively means to put all of the block groups into
a single flex_bg). However, in that case "1 << 31" is undefined on
architectures with a 32-bit integer. Fix this UBSAN complaint by
using "1U << 31" instead.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | e2fsck/pass1.c | 2 | ||||
-rw-r--r-- | lib/e2p/ls.c | 2 | ||||
-rw-r--r-- | lib/ext2fs/alloc_tables.c | 4 | ||||
-rw-r--r-- | lib/ext2fs/mkjournal.c | 2 | ||||
-rw-r--r-- | lib/ext2fs/rw_bitmaps.c | 2 | ||||
-rw-r--r-- | misc/e4defrag.c | 2 | ||||
-rw-r--r-- | resize/main.c | 2 | ||||
-rw-r--r-- | resize/resize2fs.c | 2 |
8 files changed, 9 insertions, 9 deletions
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 43972e7c6..37c5b1026 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -4067,7 +4067,7 @@ static void new_table_block(e2fsck_t ctx, blk64_t first_block, dgrp_t group, */ is_flexbg = ext2fs_has_feature_flex_bg(fs->super); if (is_flexbg) { - flexbg_size = 1 << fs->super->s_log_groups_per_flex; + flexbg_size = 1U << fs->super->s_log_groups_per_flex; flexbg = group / flexbg_size; first_block = ext2fs_group_first_block2(fs, flexbg_size * flexbg); diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c index 176bee0fd..9511d2c7a 100644 --- a/lib/e2p/ls.c +++ b/lib/e2p/ls.c @@ -312,7 +312,7 @@ void list_super2(struct ext2_super_block * sb, FILE *f) sb->s_first_meta_bg); if (sb->s_log_groups_per_flex) fprintf(f, "Flex block group size: %u\n", - 1 << sb->s_log_groups_per_flex); + 1U << sb->s_log_groups_per_flex); if (sb->s_mkfs_time) { tm = sb->s_mkfs_time; fprintf(f, "Filesystem created: %s", ctime(&tm)); diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c index 971a6ceb5..e8a1fef0e 100644 --- a/lib/ext2fs/alloc_tables.c +++ b/lib/ext2fs/alloc_tables.c @@ -43,7 +43,7 @@ static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, blk64_t last_blk, first_free = 0; dgrp_t last_grp; - flexbg_size = 1 << fs->super->s_log_groups_per_flex; + flexbg_size = 1U << fs->super->s_log_groups_per_flex; flexbg = group / flexbg_size; size = rem_grp * elem_size; @@ -97,7 +97,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, if (ext2fs_has_feature_flex_bg(fs->super) && fs->super->s_log_groups_per_flex) { - flexbg_size = 1 << fs->super->s_log_groups_per_flex; + flexbg_size = 1U << fs->super->s_log_groups_per_flex; last_grp = group | (flexbg_size - 1); if (last_grp > fs->group_desc_count-1) last_grp = fs->group_desc_count-1; diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 11d73e300..54772dd50 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -252,7 +252,7 @@ static blk64_t get_midpoint_journal_block(ext2_filsys fs) group = ext2fs_group_of_blk2(fs, (ext2fs_blocks_count(fs->super) - fs->super->s_first_data_block) / 2); - log_flex = 1 << fs->super->s_log_groups_per_flex; + log_flex = 1U << fs->super->s_log_groups_per_flex; if (fs->super->s_log_groups_per_flex && (group > log_flex)) { group = group & ~(log_flex - 1); while ((group < fs->group_desc_count) && diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 1f38010bb..b9e387302 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -527,7 +527,7 @@ errcode_t ext2fs_rw_bitmaps(ext2_filsys fs, int flags, int num_threads) pthread_mutex_t rbt_mutex = PTHREAD_MUTEX_INITIALIZER; errcode_t retval; errcode_t rc; - unsigned flexbg_size = 1 << fs->super->s_log_groups_per_flex; + unsigned flexbg_size = 1U << fs->super->s_log_groups_per_flex; dgrp_t average_group; int i, tail_flags = 0; #endif diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 86e97ee3a..9ec265f2e 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -1021,7 +1021,7 @@ static int get_best_count(ext4_fsblk_t block_count) return 1; if (feature_incompat & EXT4_FEATURE_INCOMPAT_FLEX_BG) { - flex_bg_num = 1 << log_groups_per_flex; + flex_bg_num = 1U << log_groups_per_flex; ret = ((block_count - 1) / ((ext4_fsblk_t)blocks_per_group * flex_bg_num)) + 1; diff --git a/resize/main.c b/resize/main.c index bceaa1677..c1338fbe1 100644 --- a/resize/main.c +++ b/resize/main.c @@ -111,8 +111,8 @@ static void determine_fs_stride(ext2_filsys fs) unsigned int group; unsigned long long sum; unsigned int has_sb, prev_has_sb = 0, num; + unsigned int flexbg_size = 1U << fs->super->s_log_groups_per_flex; int i_stride, b_stride; - int flexbg_size = 1 << fs->super->s_log_groups_per_flex; if (fs->stride) return; diff --git a/resize/resize2fs.c b/resize/resize2fs.c index cfc81fc78..243cd777d 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -2973,7 +2973,7 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) blk64_t grp, data_needed, last_start; blk64_t overhead = 0; int old_desc_blocks; - int flexbg_size = 1 << fs->super->s_log_groups_per_flex; + unsigned flexbg_size = 1U << fs->super->s_log_groups_per_flex; /* * first figure out how many group descriptors we need to |