0113-fs-nilfs2-Properly-bail-on-errors-in-grub_nilfs2_btr.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From ca5d9ac206043b1fb4cb06259272fb1c5946bb6d Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Mon, 18 Jan 2021 17:06:19 +1100
  4. Subject: [PATCH] fs/nilfs2: Properly bail on errors in
  5. grub_nilfs2_btree_node_lookup()
  6. We just introduced an error return in grub_nilfs2_btree_node_lookup().
  7. Make sure the callers catch it.
  8. At the same time, make sure that grub_nilfs2_btree_node_lookup() always
  9. inits the index pointer passed to it.
  10. Signed-off-by: Daniel Axtens <dja@axtens.net>
  11. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  12. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  13. ---
  14. grub-core/fs/nilfs2.c | 11 ++++++++---
  15. 1 file changed, 8 insertions(+), 3 deletions(-)
  16. diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c
  17. index 43ac1ad..aaba002 100644
  18. --- a/grub-core/fs/nilfs2.c
  19. +++ b/grub-core/fs/nilfs2.c
  20. @@ -433,7 +433,7 @@ grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data,
  21. grub_uint64_t key, int *indexp)
  22. {
  23. grub_uint64_t nkey;
  24. - int index, low, high, s;
  25. + int index = 0, low, high, s;
  26. low = 0;
  27. @@ -441,10 +441,10 @@ grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data,
  28. if (high >= grub_nilfs2_btree_node_nchildren_max (data, node))
  29. {
  30. grub_error (GRUB_ERR_BAD_FS, "too many children");
  31. + *indexp = index;
  32. return 0;
  33. }
  34. - index = 0;
  35. s = 0;
  36. while (low <= high)
  37. {
  38. @@ -526,6 +526,10 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data,
  39. level = grub_nilfs2_btree_get_level (node);
  40. found = grub_nilfs2_btree_node_lookup (data, node, key, &index);
  41. +
  42. + if (grub_errno != GRUB_ERR_NONE)
  43. + goto fail;
  44. +
  45. ptr = grub_nilfs2_btree_node_get_ptr (data, node, index);
  46. if (need_translate)
  47. ptr = grub_nilfs2_dat_translate (data, ptr);
  48. @@ -550,7 +554,8 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data,
  49. else
  50. index = 0;
  51. - if (index < grub_nilfs2_btree_node_nchildren_max (data, node))
  52. + if (index < grub_nilfs2_btree_node_nchildren_max (data, node) &&
  53. + grub_errno == GRUB_ERR_NONE)
  54. {
  55. ptr = grub_nilfs2_btree_node_get_ptr (data, node, index);
  56. if (need_translate)
  57. --
  58. 2.14.2