diff --git a/main.cpp b/main.cpp index a59ca98..8cfd0bf 100644 --- a/main.cpp +++ b/main.cpp @@ -126,6 +126,16 @@ std::map parse_headers(const std::vector return ret; } +std::string filename_sanitation(std::string filename) +{ + std::filesystem::path p(filename); + std::string ret = p.filename().string(); + if (ret == "" || ret == "." || ret == "..") + return "generic_file.txt"; + + return ret; +} + std::string get_filename(std::string data) { bool started_quote = false; @@ -139,6 +149,7 @@ std::string get_filename(std::string data) else if (started_quote) ret.push_back(x); } + ret = filename_sanitation(ret); return ret; } @@ -181,6 +192,8 @@ char *search_substring(char *start_data, const char *substring, size_t size) return NULL; } + + int main() { netlib::server_raw server(150000000); @@ -243,6 +256,8 @@ int main() else if (h.contains("Content-Length:")) { file_size = atoi_newline(h["Content-Length:"].c_str()); + if (file_size > 1000000000) //1GB + server.disconnect_user(user); } else if (line_str.contains(boundary) && boundary.contains("----")) {