Patchwork [11/31] libext2fs: ind_punch() must not stop examining blocks prematurely

login
register
mail settings
Submitter Darrick J. Wong
Date Oct. 1, 2013, 1:27 a.m.
Message ID <20131001012753.28415.4639.stgit@birch.djwong.org>
Download mbox | patch
Permalink /patch/279290/
State Accepted
Headers show

Comments

Darrick J. Wong - Oct. 1, 2013, 1:27 a.m.
When we're iterating the main loop in ind_punch(), "offset" tracks how far
we've progressed into the block map, "start" tells us where to start punching,
and "count" tells us how many blocks we are to punch after "start".  Therefore,
we would like to break out of the loop once the "offset" that we're looking at
has progressed past the end of the punch range.  Unfortunately, if start !=0,
the if-break clause in the loop causes us to break out of the loop early.

Therefore, change the breakout test to terminate the loop at the correct time.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 lib/ext2fs/punch.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o - Oct. 7, 2013, 1:43 p.m.
On Mon, Sep 30, 2013 at 06:27:53PM -0700, Darrick J. Wong wrote:
> When we're iterating the main loop in ind_punch(), "offset" tracks how far
> we've progressed into the block map, "start" tells us where to start punching,
> and "count" tells us how many blocks we are to punch after "start".  Therefore,
> we would like to break out of the loop once the "offset" that we're looking at
> has progressed past the end of the punch range.  Unfortunately, if start !=0,
> the if-break clause in the loop causes us to break out of the loop early.
> 
> Therefore, change the breakout test to terminate the loop at the correct time.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Applied, thanks.  Again, it's my bad for not including more test cases
when originally implementing the ext2fs_punch() funciton, but one of
these days, we should add better testing for this function.

      	       	      	  	 	 - Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c
index aac1942..0929400 100644
--- a/lib/ext2fs/punch.c
+++ b/lib/ext2fs/punch.c
@@ -60,7 +60,7 @@  static errcode_t ind_punch(ext2_filsys fs, struct ext2_inode *inode,
 #endif
 	incr = 1 << ((EXT2_BLOCK_SIZE_BITS(fs->super)-2)*level);
 	for (i=0, offset=0; i < max; i++, p++, offset += incr) {
-		if (offset > count)
+		if (offset >= start + count)
 			break;
 		if (*p == 0 || (offset+incr) <= start)
 			continue;