strtoull: Fix behaviour on chars between '9' and 'a'.
authorVladimir Serbinenko <phcoder@gmail.com>
Wed, 10 Aug 2016 15:49:42 +0000 (17:49 +0200)
committerVladimir Serbinenko <phcoder@gmail.com>
Wed, 3 May 2017 10:59:58 +0000 (12:59 +0200)
Reported by: Aaron Miller <aaronmiller@fb.com>

grub-core/kern/misc.c
grub-core/tests/lib/functional_test.c

index d1a54df..3b633d5 100644 (file)
@@ -391,12 +391,13 @@ grub_strtoull (const char *str, char **end, int base)
       unsigned long digit;
 
       digit = grub_tolower (*str) - '0';
-      if (digit > 9)
-       {
-         digit += '0' - 'a' + 10;
-         if (digit >= (unsigned long) base)
-           break;
-       }
+      if (digit >= 'a' - '0')
+       digit += '0' - 'a' + 10;
+      else if (digit > 9)
+       break;
+
+      if (digit >= (unsigned long) base)
+       break;
 
       found = 1;
 
index d4822a1..96781fb 100644 (file)
@@ -26,14 +26,23 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 static grub_err_t
 grub_functional_test (grub_extcmd_context_t ctxt __attribute__ ((unused)),
-                     int argc __attribute__ ((unused)),
-                     char **args __attribute__ ((unused)))
+                     int argc,
+                     char **args)
 {
   grub_test_t test;
   int ok = 1;
+  int i;
 
   FOR_LIST_ELEMENTS (test, grub_test_list)
     {
+      if (argc != 0)
+       {
+         for (i = 0; i < argc; i++)
+           if (grub_strcmp(args[i], test->name) == 0)
+             break;
+         if (i == argc)
+           continue;
+       }
       grub_errno = 0;
       ok = ok && !grub_test_run (test);
       grub_errno = 0;