From: Darrick J. Wong Date: Tue, 1 Oct 2013 01:26:55 +0000 (-0700) Subject: libext2fs: only link an inode into a directory once X-Git-Tag: v1.42.9~140 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=7320cb7106e5f5a552d07432e9322e1059c02bf3;p=tools%2Fe2fsprogs.git libext2fs: only link an inode into a directory once The ext2fs_link helper function link_proc does not check the value of ls->done, which means that if the function finds multiple empty spaces that will fit the new directory entry, it will create a directory entry in each of the spaces. Instead of doing that, check the done value and don't do anything more if we've already added the directory entry. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/link.c b/lib/ext2fs/link.c index 2d03b57..2f4f54a 100644 --- a/lib/ext2fs/link.c +++ b/lib/ext2fs/link.c @@ -42,6 +42,9 @@ static int link_proc(struct ext2_dir_entry *dirent, unsigned int rec_len, min_rec_len, curr_rec_len; int ret = 0; + if (ls->done) + return 0; + rec_len = EXT2_DIR_REC_LEN(ls->namelen); ls->err = ext2fs_get_rec_len(ls->fs, dirent, &curr_rec_len);