15a2072
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
15a2072
From: Aaron Miller <aaronmiller@fb.com>
15a2072
Date: Fri, 29 Jul 2016 17:41:27 +0800
15a2072
Subject: [PATCH] misc: fix invalid character recongition in strto*l
15a2072
15a2072
Would previously allow digits larger than the base and didn't check that
15a2072
subtracting the difference from 0-9 to lowercase letters for characters
15a2072
larger than 9 didn't result in a value lower than 9, which allowed the
15a2072
parses: ` = 9, _ = 8, ^ = 7, ] = 6, \ = 5, and [ = 4
15a2072
---
15a2072
 grub-core/kern/misc.c | 13 ++++++++-----
15a2072
 1 file changed, 8 insertions(+), 5 deletions(-)
15a2072
15a2072
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
15a2072
index 0e89c483d5e..5c3899f0e5b 100644
15a2072
--- a/grub-core/kern/misc.c
15a2072
+++ b/grub-core/kern/misc.c
15a2072
@@ -434,11 +434,14 @@ grub_strtoull (const char *str, char **end, int base)
15a2072
       unsigned long digit;
15a2072
 
15a2072
       digit = grub_tolower (*str) - '0';
15a2072
-      if (digit >= 'a' - '0')
15a2072
-	digit += '0' - 'a' + 10;
15a2072
-      else if (digit > 9)
15a2072
-	break;
15a2072
-
15a2072
+      if (digit > 9)
15a2072
+	{
15a2072
+	  digit += '0' - 'a' + 10;
15a2072
+	  /* digit <= 9 check is needed to keep chars larger than
15a2072
+	     '9' but less than 'a' from being read as numbers */
15a2072
+	  if (digit >= (unsigned long) base || digit <= 9)
15a2072
+	    break;
15a2072
+	}
15a2072
       if (digit >= (unsigned long) base)
15a2072
 	break;
15a2072