mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-18 10:59:45 +00:00
moved remove_double_dots_and_double_slashes() to string.c
This commit is contained in:
1 parent
0d2a8db626
commit
8c4521af03
3 files changed
+46
-46
No files matched your search
@@ -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';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user