Skip to content

Commit 6f1baed

Browse files
authored
Merge pull request #470 from MichaelSB/response_check_file_type
only allow regular files in set_static_file_info, return 404 in all o…
2 parents c56f101 + 97405c8 commit 6f1baed

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

include/crow/http_response.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
#include <ios>
55
#include <fstream>
66
#include <sstream>
7+
// S_ISREG is not defined for windows
8+
// This defines it like suggested in https://stackoverflow.com/a/62371749
9+
#if defined(_MSC_VER)
10+
#define _CRT_INTERNAL_NONSTDC_NAMES 1
11+
#endif
712
#include <sys/stat.h>
13+
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
14+
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
15+
#endif
816

917
#include "crow/http_request.h"
1018
#include "crow/ci_map.h"
@@ -233,7 +241,7 @@ namespace crow
233241
#ifdef CROW_ENABLE_COMPRESSION
234242
compressed = false;
235243
#endif
236-
if (file_info.statResult == 0)
244+
if (file_info.statResult == 0 && S_ISREG(file_info.statbuf.st_mode))
237245
{
238246
std::size_t last_dot = path.find_last_of(".");
239247
std::string extension = path.substr(last_dot + 1);
@@ -257,7 +265,6 @@ namespace crow
257265
{
258266
code = 404;
259267
file_info.path.clear();
260-
this->end();
261268
}
262269
}
263270

0 commit comments

Comments
 (0)