linux-nilfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
To: konishi.ryusuke@gmail.com, linux-nilfs@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, snovitoll@gmail.com
Subject: [PATCH] fs/nilfs2: prevent int overflow in btree binary search
Date: Tue,  2 Apr 2024 23:00:26 +0500	[thread overview]
Message-ID: <20240402180026.2469459-1-snovitoll@gmail.com> (raw)

Should prevent int overflow if low + high > INT_MAX in big btree with
nchildren in nilfs_btree_node_lookup() binary search.

Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
---
 fs/nilfs2/btree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index 65659fa03..39ee4fe11 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -300,7 +300,7 @@ static int nilfs_btree_node_lookup(const struct nilfs_btree_node *node,
 	index = 0;
 	s = 0;
 	while (low <= high) {
-		index = (low + high) / 2;
+		index = low + (high - low) / 2;
 		nkey = nilfs_btree_node_get_key(node, index);
 		if (nkey == key) {
 			s = 0;
-- 
2.34.1


             reply	other threads:[~2024-04-02 18:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 18:00 Sabyrzhan Tasbolatov [this message]
2024-04-02 20:55 ` [PATCH] fs/nilfs2: prevent int overflow in btree binary search Ryusuke Konishi
2024-04-03 17:08   ` Sabyrzhan Tasbolatov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240402180026.2469459-1-snovitoll@gmail.com \
    --to=snovitoll@gmail.com \
    --cc=konishi.ryusuke@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nilfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).