xref: /OK3568_Linux_fs/buildroot/boot/grub2/0098-kern-misc-Always-set-end-in-grub_strtoull.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From f41f0af48ab7f7c135aac17ac862c30bde0bbab7 Mon Sep 17 00:00:00 2001
2From: Daniel Axtens <dja@axtens.net>
3Date: Wed, 13 Jan 2021 22:19:01 +1100
4Subject: [PATCH] kern/misc: Always set *end in grub_strtoull()
5
6Currently, if there is an error in grub_strtoull(), *end is not set.
7This differs from the usual behavior of strtoull(), and also means that
8some callers may use an uninitialized value for *end.
9
10Set *end unconditionally.
11
12Signed-off-by: Daniel Axtens <dja@axtens.net>
13Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
15---
16 grub-core/kern/misc.c | 8 ++++++++
17 1 file changed, 8 insertions(+)
18
19diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
20index a7abd36..b02693b 100644
21--- a/grub-core/kern/misc.c
22+++ b/grub-core/kern/misc.c
23@@ -406,6 +406,10 @@ grub_strtoull (const char *str, char **end, int base)
24 	{
25 	  grub_error (GRUB_ERR_OUT_OF_RANGE,
26 		      N_("overflow is detected"));
27+
28+          if (end)
29+            *end = (char *) str;
30+
31 	  return ~0ULL;
32 	}
33
34@@ -417,6 +421,10 @@ grub_strtoull (const char *str, char **end, int base)
35     {
36       grub_error (GRUB_ERR_BAD_NUMBER,
37 		  N_("unrecognized number"));
38+
39+      if (end)
40+        *end = (char *) str;
41+
42       return 0;
43     }
44
45--
462.14.2
47
48