Merge pull request #470 from MichaelSB/response_check_file_type

only allow regular files in set_static_file_info, return 404 in all o…
This commit is contained in:
Farook Al-Sammarraie 2022-06-23 18:28:44 +03:00 committed by GitHub
commit 6f1baed6d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,15 @@
#include <ios>
#include <fstream>
#include <sstream>
// S_ISREG is not defined for windows
// This defines it like suggested in https://stackoverflow.com/a/62371749
#if defined(_MSC_VER)
#define _CRT_INTERNAL_NONSTDC_NAMES 1
#endif
#include <sys/stat.h>
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
#endif
#include "crow/http_request.h"
#include "crow/ci_map.h"
@ -233,7 +241,7 @@ namespace crow
#ifdef CROW_ENABLE_COMPRESSION
compressed = false;
#endif
if (file_info.statResult == 0)
if (file_info.statResult == 0 && S_ISREG(file_info.statbuf.st_mode))
{
std::size_t last_dot = path.find_last_of(".");
std::string extension = path.substr(last_dot + 1);
@ -257,7 +265,6 @@ namespace crow
{
code = 404;
file_info.path.clear();
this->end();
}
}