Commit 98e8b11c by Carlos Martín Nieto Committed by Patrick Steinhardt

path: check for a symlinked .gitmodules in fs-agnostic code

We still compare case-insensitively to protect more thoroughly as we don't know
what specifics we'll see on the system and it's the behaviour from git.
parent 1c1e32b7
...@@ -1699,6 +1699,24 @@ GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags) ...@@ -1699,6 +1699,24 @@ GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags)
} }
/* /*
* Return the length of the common prefix between str and prefix, comparing them
* case-insensitively (must be ASCII to match).
*/
GIT_INLINE(size_t) common_prefix_icase(const char *str, size_t len, const char *prefix)
{
size_t count = 0;
while (len >0 && tolower(*str) == tolower(*prefix)) {
count++;
str++;
prefix++;
len--;
}
return count;
}
/*
* We fundamentally don't like some paths when dealing with user-inputted * We fundamentally don't like some paths when dealing with user-inputted
* strings (in checkout or ref names): we don't want dot or dot-dot * strings (in checkout or ref names): we don't want dot or dot-dot
* anywhere, we want to avoid writing weird paths on Windows that can't * anywhere, we want to avoid writing weird paths on Windows that can't
...@@ -1763,13 +1781,19 @@ static bool verify_component( ...@@ -1763,13 +1781,19 @@ static bool verify_component(
*/ */
if ((flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 && if ((flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 &&
(flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 && (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 &&
(flags & GIT_PATH_REJECT_DOT_GIT_LITERAL) && (flags & GIT_PATH_REJECT_DOT_GIT_LITERAL)) {
len == 4 && if (len >= 4 &&
component[0] == '.' && component[0] == '.' &&
(component[1] == 'g' || component[1] == 'G') && (component[1] == 'g' || component[1] == 'G') &&
(component[2] == 'i' || component[2] == 'I') && (component[2] == 'i' || component[2] == 'I') &&
(component[3] == 't' || component[3] == 'T')) (component[3] == 't' || component[3] == 'T')) {
if (len == 4)
return false;
if (S_ISLNK(mode) && common_prefix_icase(component, len, ".gitmodules") == len)
return false; return false;
}
}
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment