mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
Resolve root path before serving to avoid double dots
This commit is contained in:
1 parent
92d3c7a4cd
commit
f29807aad8
1 file changed
+8
-2
@@ -5,7 +5,7 @@
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_debug_level = "2";
|
||||
static const char *s_root_dir = "."; // Attention: avoid double-dots, `..` !
|
||||
static const char *s_root_dir = NULL;
|
||||
static const char *s_listening_address = "http://localhost:8000";
|
||||
static const char *s_enable_hexdump = "no";
|
||||
static const char *s_ssi_pattern = "#.html";
|
||||
@@ -43,6 +43,8 @@ static void usage(const char *prog) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char path[MG_PATH_MAX] = ".";
|
||||
const char *root_dir = ".";
|
||||
struct mg_mgr mgr;
|
||||
struct mg_connection *c;
|
||||
int i;
|
||||
@@ -50,7 +52,7 @@ int main(int argc, char *argv[]) {
|
||||
// Parse command-line flags
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-d") == 0) {
|
||||
s_root_dir = argv[++i];
|
||||
root_dir = argv[++i];
|
||||
} else if (strcmp(argv[i], "-H") == 0) {
|
||||
s_enable_hexdump = argv[++i];
|
||||
} else if (strcmp(argv[i], "-S") == 0) {
|
||||
@@ -64,6 +66,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
// Root directory must not contain double dots. Make it absolute
|
||||
realpath(root_dir, path);
|
||||
s_root_dir = path;
|
||||
|
||||
// Initialise stuff
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
|
||||
Reference in new issue
Block a user