diff mbox

btrfs-progs: restore: fix mistake on overwrite_ok() if relative path is given

Message ID 1524035535-20385-1-git-send-email-tchou@synology.com (mailing list archive)
State New, archived
Headers show

Commit Message

tchou April 18, 2018, 7:12 a.m. UTC
From: Ting-Chang Hou <tchou@synology.com>

fstatat will return -1 with errno EBADF if path_name is relative path.
This caused an error of the return value of overwrite_ok().
When restoring the subvolume to destination with relative path,
it will overwrite the existing file rather than skip it.

Signed-off-by: tchou <tchou@synology.com>
---
 cmds-restore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba May 31, 2018, 11:56 a.m. UTC | #1
On Wed, Apr 18, 2018 at 03:12:15PM +0800, Ting-Chang wrote:
> From: Ting-Chang Hou <tchou@synology.com>
> 
> fstatat will return -1 with errno EBADF if path_name is relative path.
> This caused an error of the return value of overwrite_ok().
> When restoring the subvolume to destination with relative path,
> it will overwrite the existing file rather than skip it.
> 
> Signed-off-by: tchou <tchou@synology.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-restore.c b/cmds-restore.c
index ade35f0..dc042e2 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -825,7 +825,7 @@  static int overwrite_ok(const char * path)
 	int ret;
 
 	/* don't be fooled by symlinks */
-	ret = fstatat(-1, path_name, &st, AT_SYMLINK_NOFOLLOW);
+	ret = fstatat(AT_FDCWD, path_name, &st, AT_SYMLINK_NOFOLLOW);
 
 	if (!ret) {
 		if (overwrite)