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