From patchwork Wed Apr 18 07:12:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tchou X-Patchwork-Id: 10347421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A192060365 for ; Wed, 18 Apr 2018 07:12:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 917B42823E for ; Wed, 18 Apr 2018 07:12:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8607E28563; Wed, 18 Apr 2018 07:12:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C4B52823E for ; Wed, 18 Apr 2018 07:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752947AbeDRHMf (ORCPT ); Wed, 18 Apr 2018 03:12:35 -0400 Received: from synology.com ([59.124.61.242]:41244 "EHLO synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752882AbeDRHMc (ORCPT ); Wed, 18 Apr 2018 03:12:32 -0400 Received: from localhost.localdomain (unknown [10.13.20.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by synology.com (Postfix) with ESMTPSA id 3328B84264BF; Wed, 18 Apr 2018 15:12:31 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1524035551; bh=zoSNSX9fjGIBEVM7i2aXami4xPvbgmMQqbn0qENBdgs=; h=From:To:Cc:Subject:Date; b=UMO/5N50HIilPUL+8gaw/eurIQa7fXynwFDEmWZGM6LMaBngsD0Tztx84OUlt+q2v k+5uajrhbvnK41q96s+efrsJI2n3lieZOi/jzf8yxdLvBaONlR6RNQda7QwToa6grC 7Up6CmURXi7qWTkOa9HjLhbAbVX/X9LH0EJfqnGc= From: Ting-Chang To: linux-btrfs@vger.kernel.org Cc: Ting-Chang Hou Subject: [PATCH] btrfs-progs: restore: fix mistake on overwrite_ok() if relative path is given Date: Wed, 18 Apr 2018 15:12:15 +0800 Message-Id: <1524035535-20385-1-git-send-email-tchou@synology.com> X-Mailer: git-send-email 2.7.4 X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 5, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ting-Chang Hou 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 --- cmds-restore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)