Skip to contentSkip to conversation

f2fs: fix overflow due to condition check order

PATCH New Jaegeuk Kim 1 participant 1 message Nov 23, 2016

Subsystems (3)
lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix overflow due to condition check order

In the last ilen case, i was already increased, resulting in accessing out- of-boundary entry of do_replace and blkaddr.
Fix to check ilen first to exit the loop.

Fixes 2aa8fbb9693020 ("f2fs: refactor __exchange_data_block for speed up")
---
 fs/f2fs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/file.c +1 -1
index c786507..0237217 100644
@@ -967,7 +967,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
 				new_size = (dst + i) << PAGE_SHIFT;
 				if (dst_inode->i_size < new_size)
 					f2fs_i_size_write(dst_inode, new_size);
-			} while ((do_replace[i] || blkaddr[i] == NULL_ADDR) && --ilen);
+			} while (--ilen && (do_replace[i] || blkaddr[i] == NULL_ADDR));
 
 			f2fs_put_dnode(&dn);
 		} else {
Signature · 1 line
2.8.3