nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0166-misc-fix-invalid-character-recongition-in-strto-l.patch

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