lib/test_scanf: Handle n_bits == 0 in random tests
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 27 Jul 2021 15:01:32 +0000 (18:01 +0300)
committerPetr Mladek <pmladek@suse.com>
Thu, 29 Jul 2021 07:52:33 +0000 (09:52 +0200)
commitfe8e3ee0d588566c1f44f28a555042ef50eba491
treea45d41c48935380439bac842d5d472458c3efc0c
parente563592c3e4296780e5a184a917b8b86e126f0b3
lib/test_scanf: Handle n_bits == 0 in random tests

UBSAN reported (via LKP)

[   11.021349][    T1] UBSAN: shift-out-of-bounds in lib/test_scanf.c:275:51
[   11.022782][    T1] shift exponent 32 is too large for 32-bit type 'unsigned int'

When n_bits == 0, the shift is out of range. Switch code to use GENMASK
to handle this case.

Fixes: 50f530e176ea ("lib: test_scanf: Add tests for sscanf number conversion")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210727150132.28920-1-andriy.shevchenko@linux.intel.com
lib/test_scanf.c