moved remove_double_dots_and_double_slashes() to string.c

This commit is contained in:
Sergey Lyubka committed 2013-11-23 07:46:11 +00:00
1 parent 0d2a8db626
commit 8c4521af03
3 files changed
+46 -46

No files matched your search

+23
View File
@@ -243,3 +243,26 @@ static int match_prefix(const char *pattern, int pattern_len, const char *str) {
return j;
}
// Protect against directory disclosure attack by removing '..',
// excessive '/' and '\' characters
static void remove_double_dots_and_double_slashes(char *s) {
char *p = s;
while (*s != '\0') {
*p++ = *s++;
if (s[-1] == '/' || s[-1] == '\\') {
// Skip all following slashes, backslashes and double-dots
while (s[0] != '\0') {
if (s[0] == '/' || s[0] == '\\') {
s++;
} else if (s[0] == '.' && s[1] == '.') {
s += 2;
} else {
break;
}
}
}
}
*p = '\0';
}