nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0448-fs-nilfs2-Properly-bail-on-errors-in-grub_nilfs2_btr.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Daniel Axtens <dja@axtens.net>
9723a8
Date: Mon, 18 Jan 2021 17:06:19 +1100
9723a8
Subject: [PATCH] fs/nilfs2: Properly bail on errors in
9723a8
 grub_nilfs2_btree_node_lookup()
9723a8
9723a8
We just introduced an error return in grub_nilfs2_btree_node_lookup().
9723a8
Make sure the callers catch it.
9723a8
9723a8
At the same time, make sure that grub_nilfs2_btree_node_lookup() always
9723a8
inits the index pointer passed to it.
9723a8
9723a8
Signed-off-by: Daniel Axtens <dja@axtens.net>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/fs/nilfs2.c | 11 ++++++++---
9723a8
 1 file changed, 8 insertions(+), 3 deletions(-)
9723a8
9723a8
diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c
9723a8
index 054ad3dc18a..c4c4610bec0 100644
9723a8
--- a/grub-core/fs/nilfs2.c
9723a8
+++ b/grub-core/fs/nilfs2.c
9723a8
@@ -433,7 +433,7 @@ grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data,
9723a8
 			       grub_uint64_t key, int *indexp)
9723a8
 {
9723a8
   grub_uint64_t nkey;
9723a8
-  int index, low, high, s;
9723a8
+  int index = 0, low, high, s;
9723a8
 
9723a8
   low = 0;
9723a8
 
9723a8
@@ -441,10 +441,10 @@ grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data,
9723a8
   if (high >= grub_nilfs2_btree_node_nchildren_max (data, node))
9723a8
     {
9723a8
       grub_error (GRUB_ERR_BAD_FS, "too many children");
9723a8
+      *indexp = index;
9723a8
       return 0;
9723a8
     }
9723a8
 
9723a8
-  index = 0;
9723a8
   s = 0;
9723a8
   while (low <= high)
9723a8
     {
9723a8
@@ -526,6 +526,10 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data,
9723a8
   level = grub_nilfs2_btree_get_level (node);
9723a8
 
9723a8
   found = grub_nilfs2_btree_node_lookup (data, node, key, &index);
9723a8
+
9723a8
+  if (grub_errno != GRUB_ERR_NONE)
9723a8
+    goto fail;
9723a8
+
9723a8
   ptr = grub_nilfs2_btree_node_get_ptr (data, node, index);
9723a8
   if (need_translate)
9723a8
     ptr = grub_nilfs2_dat_translate (data, ptr);
9723a8
@@ -550,7 +554,8 @@ grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data,
9723a8
       else
9723a8
 	index = 0;
9723a8
 
9723a8
-      if (index < grub_nilfs2_btree_node_nchildren_max (data, node))
9723a8
+      if (index < grub_nilfs2_btree_node_nchildren_max (data, node) &&
9723a8
+	  grub_errno == GRUB_ERR_NONE)
9723a8
 	{
9723a8
 	  ptr = grub_nilfs2_btree_node_get_ptr (data, node, index);
9723a8
 	  if (need_translate)