2
1

0064-normal-menu-Use-safe-math-to-avoid-an-integer-overfl.patch 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. From 6fa61b113427cb9db600a4a2a2f38ce09595f15f Mon Sep 17 00:00:00 2001
  2. From: Alec Brown <alec.r.brown@oracle.com>
  3. Date: Tue, 4 Feb 2025 15:11:11 +0000
  4. Subject: [PATCH] normal/menu: Use safe math to avoid an integer overflow
  5. The Coverity indicates that the variable current_entry might overflow.
  6. To prevent this use safe math when adding GRUB_MENU_PAGE_SIZE to current_entry.
  7. On the occasion fix limiting condition which was broken.
  8. Fixes: CID 473853
  9. Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
  10. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  11. Upstream: 5b36a5210e21bee2624f8acc36aefd8f10266adb
  12. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  13. ---
  14. grub-core/normal/menu.c | 5 ++---
  15. 1 file changed, 2 insertions(+), 3 deletions(-)
  16. diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
  17. index 6a90e091f..7ac6abf93 100644
  18. --- a/grub-core/normal/menu.c
  19. +++ b/grub-core/normal/menu.c
  20. @@ -32,6 +32,7 @@
  21. #include <grub/script_sh.h>
  22. #include <grub/gfxterm.h>
  23. #include <grub/dl.h>
  24. +#include <grub/safemath.h>
  25. /* Time to delay after displaying an error message about a default/fallback
  26. entry failing to boot. */
  27. @@ -751,9 +752,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot, int *notify_boot)
  28. case GRUB_TERM_CTRL | 'c':
  29. case GRUB_TERM_KEY_NPAGE:
  30. - if (current_entry + GRUB_MENU_PAGE_SIZE < menu->size)
  31. - current_entry += GRUB_MENU_PAGE_SIZE;
  32. - else
  33. + if (grub_add (current_entry, GRUB_MENU_PAGE_SIZE, &current_entry) || current_entry >= menu->size)
  34. current_entry = menu->size - 1;
  35. menu_set_chosen_entry (current_entry);
  36. break;
  37. --
  38. 2.50.1