mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-21 11:30:01 +00:00
enhanced path sanitizing
This commit is contained in:
1 parent
4b0e34cdf4
commit
2f1a836bf0
7 files changed
+86
-79
No files matched your search
@@ -12,11 +12,13 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (mg_http_match_uri(hm, "/upload")) {
|
||||
char path[80], name[64];
|
||||
mg_http_get_var(&hm->query, "name", name, sizeof(name));
|
||||
mg_snprintf(path, sizeof(path), "/tmp/%s", name);
|
||||
if (name[0] == '\0') {
|
||||
mg_http_reply(c, 400, "", "%s", "name required");
|
||||
} else if (!mg_path_is_sane(path)) {
|
||||
mg_http_reply(c, 400, "", "%s", "invalid path");
|
||||
} else {
|
||||
mg_snprintf(path, sizeof(path), "/tmp/%s", name);
|
||||
mg_http_upload(c, hm, &mg_fs_posix, mg_remove_double_dots(path), 99999);
|
||||
mg_http_upload(c, hm, &mg_fs_posix, path, 99999);
|
||||
}
|
||||
} else {
|
||||
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
|
||||
|
||||
Reference in new issue
Block a user