bc092b9
From dc6e1b5af83eb1c4290baf97c2d221c0865127be Mon Sep 17 00:00:00 2001
bc092b9
From: Vladimir Serbinenko <phcoder@gmail.com>
bc092b9
Date: Wed, 10 Aug 2016 17:49:42 +0200
31cddd6
Subject: [PATCH] strtoull: Fix behaviour on chars between '9' and 'a'.
bc092b9
bc092b9
Reported by: Aaron Miller <aaronmiller@fb.com>
bc092b9
---
bc092b9
 grub-core/kern/misc.c                 | 13 +++++++------
bc092b9
 grub-core/tests/lib/functional_test.c | 13 +++++++++++--
bc092b9
 2 files changed, 18 insertions(+), 8 deletions(-)
bc092b9
bc092b9
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
ec4acbb
index d1a54df6c12..3b633d51f4c 100644
bc092b9
--- a/grub-core/kern/misc.c
bc092b9
+++ b/grub-core/kern/misc.c
bc092b9
@@ -391,12 +391,13 @@ grub_strtoull (const char *str, char **end, int base)
bc092b9
       unsigned long digit;
bc092b9
 
bc092b9
       digit = grub_tolower (*str) - '0';
bc092b9
-      if (digit > 9)
bc092b9
-	{
bc092b9
-	  digit += '0' - 'a' + 10;
bc092b9
-	  if (digit >= (unsigned long) base)
bc092b9
-	    break;
bc092b9
-	}
bc092b9
+      if (digit >= 'a' - '0')
bc092b9
+	digit += '0' - 'a' + 10;
bc092b9
+      else if (digit > 9)
bc092b9
+	break;
bc092b9
+
bc092b9
+      if (digit >= (unsigned long) base)
bc092b9
+	break;
bc092b9
 
bc092b9
       found = 1;
bc092b9
 
bc092b9
diff --git a/grub-core/tests/lib/functional_test.c b/grub-core/tests/lib/functional_test.c
ec4acbb
index d4822a12456..96781fb39b5 100644
bc092b9
--- a/grub-core/tests/lib/functional_test.c
bc092b9
+++ b/grub-core/tests/lib/functional_test.c
bc092b9
@@ -26,14 +26,23 @@ GRUB_MOD_LICENSE ("GPLv3+");
bc092b9
 
bc092b9
 static grub_err_t
bc092b9
 grub_functional_test (grub_extcmd_context_t ctxt __attribute__ ((unused)),
bc092b9
-		      int argc __attribute__ ((unused)),
bc092b9
-		      char **args __attribute__ ((unused)))
bc092b9
+		      int argc,
bc092b9
+		      char **args)
bc092b9
 {
bc092b9
   grub_test_t test;
bc092b9
   int ok = 1;
bc092b9
+  int i;
bc092b9
 
bc092b9
   FOR_LIST_ELEMENTS (test, grub_test_list)
bc092b9
     {
bc092b9
+      if (argc != 0)
bc092b9
+	{
bc092b9
+	  for (i = 0; i < argc; i++)
bc092b9
+	    if (grub_strcmp(args[i], test->name) == 0)
bc092b9
+	      break;
bc092b9
+	  if (i == argc)
bc092b9
+	    continue;
bc092b9
+	}
bc092b9
       grub_errno = 0;
bc092b9
       ok = ok && !grub_test_run (test);
bc092b9
       grub_errno = 0;