]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/misc: Always set *end in grub_strtoull()
authorDaniel Axtens <dja@axtens.net>
Wed, 13 Jan 2021 11:19:01 +0000 (22:19 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:17 +0000 (15:54 +0100)
Currently, if there is an error in grub_strtoull(), *end is not set.
This differs from the usual behavior of strtoull(), and also means that
some callers may use an uninitialized value for *end.

Set *end unconditionally.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/misc.c

index a278e069bde51d72a0b233f4f6bd275f162fdfbf..430e7234092ad6a63c018fc3e9cf5a0d71fd66d8 100644 (file)
@@ -419,6 +419,10 @@ grub_strtoull (const char * restrict str, const char ** const restrict end,
        {
          grub_error (GRUB_ERR_OUT_OF_RANGE,
                      N_("overflow is detected"));
+
+          if (end)
+            *end = (char *) str;
+
          return ~0ULL;
        }
 
@@ -430,6 +434,10 @@ grub_strtoull (const char * restrict str, const char ** const restrict end,
     {
       grub_error (GRUB_ERR_BAD_NUMBER,
                  N_("unrecognized number"));
+
+      if (end)
+        *end = (char *) str;
+
       return 0;
     }