mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
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:
commit
6f1baed6d3
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user