Always ignore case when forbidding .git in ObjectChecker
The component name ".GIT" inside a tree entry could confuse a case insensitive filesystem into looking at a submodule and not a directory entry. Disallow any case permutations of ".git" to prevent this confusion from entering a repository and showing up at a later date on a case insensitive system. Change-Id: Iaa3f768931d0d5764bf07ac5f6f3ff2b1fdda01b
This commit is contained in:
parent
8d36fa343c
commit
07612a610f
|
@ -1295,26 +1295,11 @@ public void testInvalidTreeNameIsGit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidTreeNameIsMixedCaseGitWindows() {
|
public void testInvalidTreeNameIsMixedCaseGit() {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
entry(b, "100644 .GiT");
|
entry(b, "100644 .GiT");
|
||||||
byte[] data = Constants.encodeASCII(b.toString());
|
byte[] data = Constants.encodeASCII(b.toString());
|
||||||
try {
|
try {
|
||||||
checker.setSafeForWindows(true);
|
|
||||||
checker.checkTree(data);
|
|
||||||
fail("incorrectly accepted an invalid tree");
|
|
||||||
} catch (CorruptObjectException e) {
|
|
||||||
assertEquals("invalid name '.GiT'", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInvalidTreeNameIsMixedCaseGitMacOS() {
|
|
||||||
StringBuilder b = new StringBuilder();
|
|
||||||
entry(b, "100644 .GiT");
|
|
||||||
byte[] data = Constants.encodeASCII(b.toString());
|
|
||||||
try {
|
|
||||||
checker.setSafeForMacOS(true);
|
|
||||||
checker.checkTree(data);
|
checker.checkTree(data);
|
||||||
fail("incorrectly accepted an invalid tree");
|
fail("incorrectly accepted an invalid tree");
|
||||||
} catch (CorruptObjectException e) {
|
} catch (CorruptObjectException e) {
|
||||||
|
|
|
@ -540,12 +540,10 @@ private static boolean isInvalidOnWindows(byte c) {
|
||||||
return 1 <= c && c <= 31;
|
return 1 <= c && c <= 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDotGit(byte[] buf, int p) {
|
private static boolean isDotGit(byte[] buf, int p) {
|
||||||
if (windows || macosx)
|
|
||||||
return toLower(buf[p]) == 'g'
|
return toLower(buf[p]) == 'g'
|
||||||
&& toLower(buf[p + 1]) == 'i'
|
&& toLower(buf[p + 1]) == 'i'
|
||||||
&& toLower(buf[p + 2]) == 't';
|
&& toLower(buf[p + 2]) == 't';
|
||||||
return buf[p] == 'g' && buf[p + 1] == 'i' && buf[p + 2] == 't';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char toLower(byte b) {
|
private static char toLower(byte b) {
|
||||||
|
|
Loading…
Reference in New Issue