[PATCH v4 4/6] lib/cmdline: Fix get_option() for strings starting with hyphen

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Fixes: f68565831e72 ("Import 2.4.0-test2pre3")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
v4: new patch
 lib/cmdline.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/cmdline.c b/lib/cmdline.c
index fbb9981a04a4..ca89846ee0bb 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -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)
@@ -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 == ',') {
-- 
2.28.0




[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux