Skip to content

Commit

Permalink
lib/cmdline: fix get_option() for strings starting with hyphen
Browse files Browse the repository at this point in the history
When string doesn't have an integer and starts from hyphen get_option()
may return interesting results.  Fix it to return 0.

The simple_strtoull() is used due to absence of simple_strtoul() in a boot
code on some architectures.

Note, the Fixes tag below is rather for anthropological curiosity.

Link: https://lkml.kernel.org/r/20201112180732.75589-4-andriy.shevchenko@linux.intel.com
Fixes: f68565831e72 ("Import 2.4.0-test2pre3")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: David Gow <davidgow@google.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Cc: Vitor Massaru Iha <vitor@massaru.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Andy Shevchenko authored and Linus Torvalds committed Dec 16, 2020
1 parent 45e3d5a commit e291851
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ static int get_range(char **str, int *pint, int n)
* 1 - int found, no subsequent comma
* 2 - int found including a subsequent comma
* 3 - hyphen found to denote a range
*
* Leading hyphen without integer is no integer case, but we consume it
* for the sake of simplification.
*/

int get_option(char **str, int *pint)
Expand All @@ -53,7 +56,10 @@ int get_option(char **str, int *pint)

if (!cur || !(*cur))
return 0;
*pint = simple_strtol(cur, str, 0);
if (*cur == '-')
*pint = -simple_strtoull(++cur, str, 0);
else
*pint = simple_strtoull(cur, str, 0);
if (cur == *str)
return 0;
if (**str == ',') {
Expand Down

0 comments on commit e291851

Please sign in to comment.