dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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