Blame SOURCES/git-cve-2018-17456-tests.patch

647f52
From 90243e8192574f43bb84be01528504ec230d7fd3 Mon Sep 17 00:00:00 2001
647f52
From: Pavel Cahyna <pcahyna@redhat.com>
647f52
Date: Fri, 19 Oct 2018 10:55:43 +0200
647f52
Subject: [PATCH 2/2] submodule-config: ban submodule urls that start with dash
647f52
 - tests
647f52
647f52
Our tests cover two cases:
647f52
647f52
  1. A file url with "./" continues to work, showing that
647f52
     there's an escape hatch for people with truly silly
647f52
     repo names.
647f52
647f52
  2. A url starting with "-" is rejected.
647f52
647f52
Note that we expect case (2) to fail, but it would have done
647f52
so even without this commit, for the reasons given above.
647f52
So instead of just expecting failure, let's also check for
647f52
the magic word "ignoring" on stderr. That lets us know that
647f52
we failed for the right reason.
647f52
647f52
[pc: backported to 1.8.3.1 by avoiding -C in tests]
647f52
647f52
submodule-config: ban submodule paths that start with a dash - test
647f52
647f52
There are two minor differences to the tests in t7416 (that
647f52
covered urls):
647f52
647f52
  1. We don't have a "./-sub" escape hatch to make this
647f52
     work, since the submodule code expects to be able to
647f52
     match canonical index names to the path field (so you
647f52
     are free to add submodule config with that path, but we
647f52
     would never actually use it, since an index entry would
647f52
     never start with "./").
647f52
647f52
  2. After this patch, cloning actually succeeds. Since we
647f52
     ignore the submodule.*.path value, we fail to find a
647f52
     config stanza for our submodule at all, and simply
647f52
     treat it as inactive. We still check for the "ignoring"
647f52
     message.
647f52
647f52
[jn:
647f52
 - the original patch expects 'git clone' to succeed in
647f52
   the test because v2.13.0-rc0~10^2~3 (clone: teach
647f52
   --recurse-submodules to optionally take a pathspec,
647f52
   2017-03-17) makes 'git clone' skip invalid submodules.
647f52
   Updated the test to pass in older Git versions where the
647f52
   submodule name check makes 'git clone' fail.]
647f52
647f52
[pc:
647f52
 - avoid -C in tests
647f52
 - reimplement git mv of a submodule, git mv gained that functionality later.]
647f52
647f52
fsck: detect submodule urls starting with dash - tests
647f52
647f52
[pc: backported to 1.8.3.1 by avoiding -C in tests ]
647f52
647f52
fsck: detect submodule paths starting with dash - test
647f52
647f52
commit 1a7fd1fb2998002da6e9ff2ee46e1bdd25ee8404 upstream.
647f52
647f52
[pc: backported to 1.8.3.1 by avoiding -C in tests ]
647f52
---
647f52
 t/t7416-submodule-dash-url.sh | 49 +++++++++++++++++++++++++++++++++++++++++++
647f52
 t/t7417-submodule-path-url.sh | 32 ++++++++++++++++++++++++++++
647f52
 2 files changed, 81 insertions(+)
647f52
 create mode 100755 t/t7416-submodule-dash-url.sh
647f52
 create mode 100755 t/t7417-submodule-path-url.sh
647f52
647f52
diff --git a/t/t7416-submodule-dash-url.sh b/t/t7416-submodule-dash-url.sh
647f52
new file mode 100755
647f52
index 000000000..e85f2e9d2
647f52
--- /dev/null
647f52
+++ b/t/t7416-submodule-dash-url.sh
647f52
@@ -0,0 +1,49 @@
647f52
+#!/bin/sh
647f52
+
647f52
+test_description='check handling of .gitmodule url with dash'
647f52
+. ./test-lib.sh
647f52
+
647f52
+test_expect_success 'create submodule with protected dash in url' '
647f52
+	git init upstream &&
647f52
+	( cd upstream && git commit --allow-empty -m base ) &&
647f52
+	mv upstream ./-upstream &&
647f52
+	git submodule add ./-upstream sub &&
647f52
+	git add sub .gitmodules &&
647f52
+	git commit -m submodule
647f52
+'
647f52
+
647f52
+test_expect_success 'clone can recurse submodule' '
647f52
+	test_when_finished "rm -rf dst" &&
647f52
+	git clone --recurse-submodules . dst &&
647f52
+	echo base >expect &&
647f52
+	( cd dst/sub && git log -1 --format=%s ) >actual &&
647f52
+	test_cmp expect actual
647f52
+'
647f52
+
647f52
+test_expect_success 'fsck accepts protected dash' '
647f52
+	test_when_finished "rm -rf dst" &&
647f52
+	git init --bare dst &&
647f52
+	( cd dst && git config transfer.fsckObjects true ) &&
647f52
+	git push dst HEAD
647f52
+'
647f52
+
647f52
+test_expect_success 'remove ./ protection from .gitmodules url' '
647f52
+	perl -i -pe "s{\./}{}" .gitmodules &&
647f52
+	git commit -am "drop protection"
647f52
+'
647f52
+
647f52
+test_expect_success 'clone rejects unprotected dash' '
647f52
+	test_when_finished "rm -rf dst" &&
647f52
+	test_must_fail git clone --recurse-submodules . dst 2>err &&
647f52
+	test_i18ngrep "may be interpreted as a command-line option" err
647f52
+'
647f52
+
647f52
+test_expect_success 'fsck rejects unprotected dash' '
647f52
+	test_when_finished "rm -rf dst" &&
647f52
+	git init --bare dst &&
647f52
+	( cd dst && git config transfer.fsckObjects true ) &&
647f52
+	test_must_fail git push dst HEAD 2>err &&
647f52
+	test_i18ngrep "disallowed submodule url" err
647f52
+'
647f52
+
647f52
+test_done
647f52
diff --git a/t/t7417-submodule-path-url.sh b/t/t7417-submodule-path-url.sh
647f52
new file mode 100755
647f52
index 000000000..141b42a11
647f52
--- /dev/null
647f52
+++ b/t/t7417-submodule-path-url.sh
647f52
@@ -0,0 +1,32 @@
647f52
+#!/bin/sh
647f52
+
647f52
+test_description='check handling of .gitmodule path with dash'
647f52
+. ./test-lib.sh
647f52
+
647f52
+test_expect_success 'create submodule with dash in path' '
647f52
+	git init upstream &&
647f52
+	( cd upstream && git commit --allow-empty -m base ) &&
647f52
+	git submodule add ./upstream sub &&
647f52
+        mv -- sub -sub &&
647f52
+        git rm --cached sub &&
647f52
+        sed -i -e "/=.*sub$/s/sub/-sub/" .git/modules/sub/config &&
647f52
+        sed -i -e "/=.*sub$/s/sub/-sub/" .gitmodules &&
647f52
+        git add -- -sub .git/modules/sub/config .gitmodules &&
647f52
+	git commit -m submodule
647f52
+'
647f52
+
647f52
+test_expect_success 'clone rejects unprotected dash' '
647f52
+	test_when_finished "rm -rf dst" &&
647f52
+	test_might_fail git clone --recurse-submodules . dst 2>err &&
647f52
+	test_i18ngrep "may be interpreted as a command-line option" err
647f52
+'
647f52
+
647f52
+test_expect_success 'fsck rejects unprotected dash' '
647f52
+	test_when_finished "rm -rf dst" &&
647f52
+	git init --bare dst &&
647f52
+	( cd dst && git config transfer.fsckObjects true ) &&
647f52
+	test_must_fail git push dst HEAD 2>err &&
647f52
+	test_i18ngrep "disallowed submodule path" err
647f52
+'
647f52
+
647f52
+test_done
647f52
-- 
647f52
2.14.4
647f52