change mg_path_is_sane()

This commit is contained in:
Sergio R. Caprile committed 2024-04-22 11:27:22 -03:00
1 parent e1ccdc0570
commit 6697a2cfaa
9 files changed
+45 -34

No files matched your search

+6 -5
View File
@@ -173,11 +173,12 @@ void mg_unhex(const char *buf, size_t len, unsigned char *to) {
}
}
bool mg_path_is_sane(const char *path) {
const char *s = path;
if (path[0] == '.' && path[1] == '.') return false; // Starts with ..
for (; s[0] != '\0'; s++) {
if (s[0] == '/' || s[0] == '\\') { // Subdir?
bool mg_path_is_sane(const struct mg_str path) {
const char *s = path.buf;
size_t n = path.len;
if (path.buf[0] == '.' && path.buf[1] == '.') return false; // Starts with ..
for (; s[0] != '\0' && n > 0; s++, n--) {
if ((s[0] == '/' || s[0] == '\\') && n >= 2) { // Subdir?
if (s[1] == '.' && s[2] == '.') return false; // Starts with ..
}
}