0098-kern-misc-Always-set-end-in-grub_strtoull.patch 1.3 KB

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