From 1f4ef8a4def50cca2bea793f04fc6f1ac2fac041 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 21 Oct 2024 12:16:24 +0300 Subject: [PATCH] fix 'access denied' in file.remove for entry points 'export', 'config' --- src/logic/scripting/lua/libs/libfile.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/logic/scripting/lua/libs/libfile.cpp b/src/logic/scripting/lua/libs/libfile.cpp index 52f7e4db..c114f00b 100644 --- a/src/logic/scripting/lua/libs/libfile.cpp +++ b/src/logic/scripting/lua/libs/libfile.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "coders/gzip.hpp" #include "engine.hpp" @@ -53,11 +54,15 @@ static int l_file_write(lua::State* L) { return 1; } +static std::set writeable_entry_points { + "world", "export", "config" +}; + static int l_file_remove(lua::State* L) { std::string rawpath = lua::require_string(L, 1); fs::path path = resolve_path(rawpath); auto entryPoint = rawpath.substr(0, rawpath.find(':')); - if (entryPoint != "world") { + if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) { throw std::runtime_error("access denied"); } return lua::pushboolean(L, fs::remove(path)); @@ -67,7 +72,7 @@ static int l_file_remove_tree(lua::State* L) { std::string rawpath = lua::require_string(L, 1); fs::path path = resolve_path(rawpath); auto entryPoint = rawpath.substr(0, rawpath.find(':')); - if (entryPoint != "world") { + if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) { throw std::runtime_error("access denied"); } return lua::pushinteger(L, fs::remove_all(path));