From patchwork Mon Oct 5 12:16:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11816557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0FDE618 for ; Mon, 5 Oct 2020 12:17:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA4E02085B for ; Mon, 5 Oct 2020 12:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726329AbgJEMQ6 (ORCPT ); Mon, 5 Oct 2020 08:16:58 -0400 Received: from cloud.peff.net ([104.130.231.41]:49616 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbgJEMQu (ORCPT ); Mon, 5 Oct 2020 08:16:50 -0400 Received: (qmail 32279 invoked by uid 109); 5 Oct 2020 12:16:49 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Mon, 05 Oct 2020 12:16:49 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 19089 invoked by uid 111); 5 Oct 2020 12:16:48 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Mon, 05 Oct 2020 08:16:48 -0400 Authentication-Results: peff.net; auth=none Date: Mon, 5 Oct 2020 08:16:48 -0400 From: Jeff King To: git@vger.kernel.org Cc: Jonathan Nieder Subject: [PATCH v2 8/8] fsck: complain when .gitattributes or .gitignore is a symlink Message-ID: <20201005121648.GH2907394@coredump.intra.peff.net> References: <20201005121609.GA2907272@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201005121609.GA2907272@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The previous commit made it impossible to have a symlinked .gitattributes or .gitignore file via verify_path(). Let's add the same check to fsck, which matches how we handle .gitmodules symlinks, via b7b1fca175 (fsck: complain when .gitmodules is a symlink, 2018-05-04). Note that we won't add these to the existing gitmodules block. The logic for gitmodules is a bit more complicated, as we also check the content of non-symlink instances we find. But for these new files, there is no content check; we're just looking at the name and mode of the tree entry (and we can avoid even the complicated name checks in the common case that the mode doesn't indicate a symlink). We can reuse the test helper function we defined for .gitmodules, though (and this covers the verify_path() change from the previous commit, as well). Signed-off-by: Jeff King --- fsck.c | 15 +++++++++++++++ t/t7450-bad-dotgitx-files.sh | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/fsck.c b/fsck.c index 024810139b..fcd3f268b1 100644 --- a/fsck.c +++ b/fsck.c @@ -67,6 +67,8 @@ static struct oidset gitmodules_done = OIDSET_INIT; FUNC(GITMODULES_URL, ERROR) \ FUNC(GITMODULES_PATH, ERROR) \ FUNC(GITMODULES_UPDATE, ERROR) \ + FUNC(GITIGNORE_SYMLINK, ERROR) \ + FUNC(GITATTRIBUTES_SYMLINK, ERROR) \ /* warnings */ \ FUNC(BAD_FILEMODE, WARN) \ FUNC(EMPTY_NAME, WARN) \ @@ -688,6 +690,19 @@ static int fsck_tree(const struct object_id *tree_oid, ".gitmodules is a symbolic link"); } + if (S_ISLNK(mode)) { + if (is_hfs_dotgitignore(name) || + is_ntfs_dotgitignore(name)) + retval += report(options, tree_oid, OBJ_TREE, + FSCK_MSG_GITIGNORE_SYMLINK, + ".gitignore is a symlink"); + if (is_hfs_dotgitattributes(name) || + is_ntfs_dotgitattributes(name)) + retval += report(options, tree_oid, OBJ_TREE, + FSCK_MSG_GITATTRIBUTES_SYMLINK, + ".gitattributes is a symlink"); + } + if ((backslash = strchr(name, '\\'))) { while (backslash) { backslash++; diff --git a/t/t7450-bad-dotgitx-files.sh b/t/t7450-bad-dotgitx-files.sh index 0cd0f71c39..326b34e167 100755 --- a/t/t7450-bad-dotgitx-files.sh +++ b/t/t7450-bad-dotgitx-files.sh @@ -193,6 +193,14 @@ check_forbidden_symlink gitmodules vanilla .gitmodules check_forbidden_symlink gitmodules ntfs ".gitmodules ." check_forbidden_symlink gitmodules hfs ".${u200c}gitmodules" +check_forbidden_symlink gitattributes vanilla .gitattributes +check_forbidden_symlink gitattributes ntfs ".gitattributes ." +check_forbidden_symlink gitattributes hfs ".${u200c}gitattributes" + +check_forbidden_symlink gitignore vanilla .gitignore +check_forbidden_symlink gitignore ntfs ".gitignore ." +check_forbidden_symlink gitignore hfs ".${u200c}gitignore" + test_expect_success 'fsck detects non-blob .gitmodules' ' git init non-blob && (