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

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