git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] fsck: make symlinked .gitignore and .gitattributes a warning

From
Jeff King <peff@peff.net>
Date
Feb 15, 2021, 23:18 UTC
Message-ID
<YCsBRUQkrAm8l2gz@coredump.intra.peff.net>
In-Reply-To
<YCsBA002yv8XpppM@coredump.intra.peff.net>

We recently added fsck checks to complain about symlinked .gitignore and .gitattributes files, which are no longer allowed to be checked out. This is partially to inform fsck users of the problem, but also to protect older clients from receiving them (by blocking push and fetch via transfer.fsckObjects).

While there are some minor security implications to having these files be symlinks, this is out-weighed by the inconvenience of blocking historical commits in some projects that might include them.

Let's loosen the fsck check to a warning. It will continue to be reported by both git-fsck and transfer.fsckObjects, but will not impact the exit code or the acceptance of objects. Note that internally in fsck.c this is called "INFO", but the word "warning" will appear in user-visible output.

Signed-off-by: Jeff King <peff@peff.net>
---
 fsck.c                       |  4 ++--
 t/t7450-bad-dotgitx-files.sh | 26 ++++++++++++++++++--------
 2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/fsck.c b/fsck.c
index d0a201348d..c75c7d7dc7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -67,8 +67,6 @@ 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) \
@@ -81,6 +79,8 @@ static struct oidset gitmodules_done = OIDSET_INIT;
 	FUNC(NUL_IN_COMMIT, WARN) \
 	/* infos (reported as warnings, but ignored by default) */ \
 	FUNC(GITMODULES_PARSE, INFO) \
+	FUNC(GITIGNORE_SYMLINK, INFO) \
+	FUNC(GITATTRIBUTES_SYMLINK, INFO) \
 	FUNC(BAD_TAG_NAME, INFO) \
 	FUNC(MISSING_TAGGER_ENTRY, INFO) \
 	/* ignored (elevated when requested) */ \
diff --git a/t/t7450-bad-dotgitx-files.sh b/t/t7450-bad-dotgitx-files.sh
index 326b34e167..4b1edb150e 100755
--- a/t/t7450-bad-dotgitx-files.sh
+++ b/t/t7450-bad-dotgitx-files.sh
@@ -140,6 +140,16 @@ test_expect_success 'index-pack --strict works for non-repo pack' '
 '
 
 check_forbidden_symlink () {
+	fsck_must_fail=test_must_fail
+	fsck_prefix=error
+	case "$1" in
+	--fsck-warning)
+		fsck_must_fail=
+		fsck_prefix=warning
+		shift
+		;;
+	esac
+
 	name=$1
 	type=$2
 	path=$3
@@ -172,8 +182,8 @@ check_forbidden_symlink () {
 
 			# Check not only that we fail, but that it is due to the
 			# symlink detector
-			test_must_fail git fsck 2>output &&
-			test_i18ngrep "tree $tree: ${name}Symlink" output
+			$fsck_must_fail git fsck 2>output &&
+			test_i18ngrep "$fsck_prefix.*tree $tree: ${name}Symlink" output
 		)
 	'
 
@@ -193,13 +203,13 @@ 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 --fsck-warning gitattributes vanilla .gitattributes
+check_forbidden_symlink --fsck-warning gitattributes ntfs ".gitattributes ."
+check_forbidden_symlink --fsck-warning gitattributes hfs ".${u200c}gitattributes"
 
-check_forbidden_symlink gitignore vanilla .gitignore
-check_forbidden_symlink gitignore ntfs ".gitignore ."
-check_forbidden_symlink gitignore hfs ".${u200c}gitignore"
+check_forbidden_symlink --fsck-warning gitignore vanilla .gitignore
+check_forbidden_symlink --fsck-warning gitignore ntfs ".gitignore ."
+check_forbidden_symlink --fsck-warning gitignore hfs ".${u200c}gitignore"
 
 test_expect_success 'fsck detects non-blob .gitmodules' '
 	git init non-blob &&
-- 
2.30.1.986.gd86016a168
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 3 of 25 in “Limited local file inclusion with .mailmap symlinks and git-archive”
  1. Blake BurkhartFeb 13, 2021
  2. Jeff KingFeb 15, 2021
  3. 1/2 fsck: make symlinked .gitignore and .gitattributes a warningJeff King, Feb 15, 2021
  4. Ævar Arnfjörð BjarmasonFeb 16, 2021
  5. Jeff KingFeb 16, 2021
  6. Junio C HamanoFeb 16, 2021
  7. Jeff KingFeb 16, 2021
  8. Jeff KingFeb 16, 2021
  9. 0/6 open in-tree files with O_NOFOLLOWJeff King, Feb 16, 2021
  10. 1/6 add open_nofollow() helperJeff King, Feb 16, 2021
  11. Jeff KingFeb 16, 2021
  12. Taylor BlauFeb 16, 2021
  13. Jeff KingFeb 16, 2021
  14. Taylor BlauFeb 16, 2021
  15. Taylor BlauFeb 16, 2021
  16. Jeff KingFeb 16, 2021
  17. 2/6 attr: convert "macro_ok" into a flags fieldJeff King, Feb 16, 2021
  18. 4/6 attr: do not respect symlinks for in-tree .gitattributesJeff King, Feb 16, 2021
  19. 5/6 exclude: do not respect symlinks for in-tree .gitignoreJeff King, Feb 16, 2021
  20. 3/6 exclude: add flags parameter to add_patterns()Jeff King, Feb 16, 2021
  21. 6/6 mailmap: do not respect symlinks for in-tree .mailmapJeff King, Feb 16, 2021
  22. Jeff KingFeb 16, 2021
  23. Junio C HamanoFeb 25, 2021
  24. Jeff KingFeb 26, 2021
  25. 2/2 disallow symlinked .mailmap filesJeff King, Feb 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.