Commit 76495ec1 authored by Lukas Czerner's avatar Lukas Czerner Committed by Theodore Ts'o

ext4: fix undefined bit shift result in ext4_fill_flex_info

The result of the bit shift expression in
'1 << sbi->s_log_groups_per_flex' can be undefined in the case that
s_log_groups_per_flex is 31 because the result of the shift is bigger
than INT_MAX. In reality this probably should not cause much problems
since we'll end up with INT_MIN which will then be converted into
'unsigned int' type, but nevertheless according to the ISO C99 the
result is actually undefined.

Fix this by changing the left operand to 'unsigned int' type.

Note that the commit d50f2ab6 already
tried to fix the undefined behaviour, but this was missed.

Thanks to Laszlo Ersek for pointing this out and suggesting the fix.
Signed-off-by: default avatarLukas Czerner <lczerner@redhat.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: default avatarCarlos Maiolino <cmaiolino@redhat.com>
Reported-by: default avatarLaszlo Ersek <lersek@redhat.com>
parent 06db49e6
...@@ -1970,7 +1970,7 @@ static int ext4_fill_flex_info(struct super_block *sb) ...@@ -1970,7 +1970,7 @@ static int ext4_fill_flex_info(struct super_block *sb)
sbi->s_log_groups_per_flex = 0; sbi->s_log_groups_per_flex = 0;
return 1; return 1;
} }
groups_per_flex = 1 << sbi->s_log_groups_per_flex; groups_per_flex = 1U << sbi->s_log_groups_per_flex;
err = ext4_alloc_flex_bg_array(sb, sbi->s_groups_count); err = ext4_alloc_flex_bg_array(sb, sbi->s_groups_count);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment