summaryrefslogtreecommitdiff
path: root/t/t4129-apply-samemode.sh
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-06-27 17:03:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-27 17:59:38 (GMT)
commit44e5471a8d8ec5f04058220f8b91513b5b5accaa (patch)
tree51047bfed6263f86d712faac43760124249bb6e1 /t/t4129-apply-samemode.sh
parent4269974179ff4fc2a970c972330ba5b7f26a323b (diff)
downloadgit-44e5471a8d8ec5f04058220f8b91513b5b5accaa.zip
git-44e5471a8d8ec5f04058220f8b91513b5b5accaa.tar.gz
git-44e5471a8d8ec5f04058220f8b91513b5b5accaa.tar.bz2
apply: check git diffs for invalid file modes
An empty string as mode specification is accepted silently by git apply, as Vegard Nossum found out using AFL. It's interpreted as zero. Reject such bogus file modes, and only accept ones consisting exclusively of octal digits. Reported-by: Vegard Nossum <vegard.nossum@oracle.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4129-apply-samemode.sh')
-rwxr-xr-xt/t4129-apply-samemode.sh16
1 files changed, 15 insertions, 1 deletions
diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh
index c268298..5cdd76d 100755
--- a/t/t4129-apply-samemode.sh
+++ b/t/t4129-apply-samemode.sh
@@ -13,7 +13,9 @@ test_expect_success setup '
echo modified >file &&
git diff --stat -p >patch-0.txt &&
chmod +x file &&
- git diff --stat -p >patch-1.txt
+ git diff --stat -p >patch-1.txt &&
+ sed "s/^\(new mode \).*/\1/" <patch-1.txt >patch-empty-mode.txt &&
+ sed "s/^\(new mode \).*/\1garbage/" <patch-1.txt >patch-bogus-mode.txt
'
test_expect_success FILEMODE 'same mode (no index)' '
@@ -59,4 +61,16 @@ test_expect_success FILEMODE 'mode update (index only)' '
git ls-files -s file | grep "^100755"
'
+test_expect_success FILEMODE 'empty mode is rejected' '
+ git reset --hard &&
+ test_must_fail git apply patch-empty-mode.txt 2>err &&
+ test_i18ngrep "invalid mode" err
+'
+
+test_expect_success FILEMODE 'bogus mode is rejected' '
+ git reset --hard &&
+ test_must_fail git apply patch-bogus-mode.txt 2>err &&
+ test_i18ngrep "invalid mode" err
+'
+
test_done