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

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