Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-ext4@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Yongqiang Yang <xiaoqiangnk@gmail.com>
Subject: [RFC] ext4: off by one check in ext4_ext_convert_to_initialized()
Date: Sat, 23 Jun 2012 12:15:20 +0300	[thread overview]
Message-ID: <20120623091520.GB26923@elgon.mountain> (raw)

I am not very familiar with this code, but I think that we should be
using "<= EXT4_EXT_ZERO_LEN" here instead of "< EXT4_EXT_ZERO_LEN".

1)  The other comparisons with EXT4_EXT_ZERO_LEN use "<=".

2)  On the first side of the if else statement we do:
	if (allocated <= EXT4_EXT_ZERO_LEN ...
		split_map.m_len = allocated;
    On this side, it would match to do:
	if (map->m_lblk - ee_block + map->m_len <= EXT4_EXT_ZERO_LEN ...
		split_map.m_len = map->m_lblk - ee_block + map->m_len;

It's not the most air tight of arguments, so I've submitted this with a
big warning message.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 91341ec..2df32a4 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3208,7 +3208,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
 				goto out;
 			split_map.m_lblk = map->m_lblk;
 			split_map.m_len = allocated;
-		} else if ((map->m_lblk - ee_block + map->m_len <
+		} else if ((map->m_lblk - ee_block + map->m_len <=
 			   EXT4_EXT_ZERO_LEN) &&
 			   (EXT4_EXT_MAY_ZEROOUT & split_flag)) {
 			/* case 2 */

                 reply	other threads:[~2012-06-23  9:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20120623091520.GB26923@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=xiaoqiangnk@gmail.com \
    /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