mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 06:51:51 +00:00
Merge pull request #1032 from MihailRis/fix-security-issues
Some checks failed
Build / Build (push) Waiting to run
x86-64 AppImage / build-appimage (ubuntu-22.04) (push) Has been cancelled
Macos Build / build-dmg (push) Has been cancelled
Windows Build (CLang) / build-windows (clang, windows-latest) (push) Has been cancelled
MSVC Build / build-windows (windows-2022) (push) Has been cancelled
Some checks failed
Build / Build (push) Waiting to run
x86-64 AppImage / build-appimage (ubuntu-22.04) (push) Has been cancelled
Macos Build / build-dmg (push) Has been cancelled
Windows Build (CLang) / build-windows (clang, windows-latest) (push) Has been cancelled
MSVC Build / build-windows (windows-2022) (push) Has been cancelled
0.32.4 patch
This commit is contained in:
commit
ca066f46a6
7 changed files with 63 additions and 8 deletions
|
|
@ -133,6 +133,9 @@ static model::Mesh load_mesh(
|
||||||
if (flags == FLAG_ZLIB) {
|
if (flags == FLAG_ZLIB) {
|
||||||
throw std::runtime_error("compression is not supported yet");
|
throw std::runtime_error("compression is not supported yet");
|
||||||
}
|
}
|
||||||
|
if (attributeCount <= 0) {
|
||||||
|
throw std::runtime_error("mesh must have at least one attribute");
|
||||||
|
}
|
||||||
std::vector<VertexAttribute> attributes;
|
std::vector<VertexAttribute> attributes;
|
||||||
for (int i = 0; i < attributeCount; i++) {
|
for (int i = 0; i < attributeCount; i++) {
|
||||||
attributes.push_back(load_attribute(reader));
|
attributes.push_back(load_attribute(reader));
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,29 @@ StdfsDevice::StdfsDevice(fs::path root, bool createDirectory)
|
||||||
<< ": " << ec.message();
|
<< ": " << ec.message();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
absoluteRoot = fs::absolute(this->root).lexically_normal();
|
||||||
|
if (!absoluteRoot.has_filename() && absoluteRoot.has_relative_path()) {
|
||||||
|
absoluteRoot = absoluteRoot.parent_path();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path StdfsDevice::resolve(std::string_view path) {
|
fs::path StdfsDevice::resolve(std::string_view path) {
|
||||||
return root / fs::u8path(io::path(std::string(path)).normalized().string());
|
if (path.find_first_of(std::string_view("\0\\:", 3)) != std::string_view::npos) {
|
||||||
|
throw std::runtime_error("invalid path");
|
||||||
|
}
|
||||||
|
fs::path rel = fs::u8path(io::path(std::string(path)).normalized().string());
|
||||||
|
if (rel.has_root_name() || rel.has_root_directory()) {
|
||||||
|
throw std::runtime_error("absolute paths are not allowed");
|
||||||
|
}
|
||||||
|
fs::path full = (absoluteRoot / rel).lexically_normal();
|
||||||
|
fs::path inside = full.lexically_relative(absoluteRoot);
|
||||||
|
if (inside.empty() || *inside.begin() == "..") {
|
||||||
|
throw std::runtime_error("path escapes device root");
|
||||||
|
}
|
||||||
|
if (inside == ".") {
|
||||||
|
return absoluteRoot;
|
||||||
|
}
|
||||||
|
return full;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::ostream> StdfsDevice::write(std::string_view path) {
|
std::unique_ptr<std::ostream> StdfsDevice::write(std::string_view path) {
|
||||||
|
|
@ -90,17 +109,32 @@ bool StdfsDevice::mkdirs(std::string_view path) {
|
||||||
|
|
||||||
bool StdfsDevice::remove(std::string_view path) {
|
bool StdfsDevice::remove(std::string_view path) {
|
||||||
auto resolved = resolve(path);
|
auto resolved = resolve(path);
|
||||||
return fs::remove(resolved);
|
if (resolved == absoluteRoot) {
|
||||||
|
throw std::runtime_error("unable to remove device root");
|
||||||
|
}
|
||||||
|
std::error_code ec;
|
||||||
|
bool removed = fs::remove(resolved, ec);
|
||||||
|
if (ec) {
|
||||||
|
logger.error() << "error removing " << resolved << ": " << ec.message();
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t StdfsDevice::removeAll(std::string_view path) {
|
uint64_t StdfsDevice::removeAll(std::string_view path) {
|
||||||
auto resolved = resolve(path);
|
auto resolved = resolve(path);
|
||||||
if (fs::exists(resolved)) {
|
if (resolved == absoluteRoot) {
|
||||||
logger.info() << "removeAll " << resolved;
|
throw std::runtime_error("unable to remove device root");
|
||||||
return fs::remove_all(resolved);
|
}
|
||||||
} else {
|
std::error_code ec;
|
||||||
|
auto removed = fs::remove_all(resolved, ec);
|
||||||
|
if (ec) {
|
||||||
|
logger.error() << "error removing " << resolved << ": " << ec.message();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (removed > 0) {
|
||||||
|
logger.info() << "removeAll " << resolved << ": " << removed;
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StdfsPathsGenerator : public PathsGenerator {
|
class StdfsPathsGenerator : public PathsGenerator {
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,6 @@ namespace io {
|
||||||
std::unique_ptr<PathsGenerator> list(std::string_view path) override;
|
std::unique_ptr<PathsGenerator> list(std::string_view path) override;
|
||||||
private:
|
private:
|
||||||
std::filesystem::path root;
|
std::filesystem::path root;
|
||||||
|
std::filesystem::path absoluteRoot;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,9 @@ std::vector<ubyte> io::read_bytes(const path& filename) {
|
||||||
std::string io::read_string(const path& filename) {
|
std::string io::read_string(const path& filename) {
|
||||||
size_t size;
|
size_t size;
|
||||||
auto bytes = read_bytes(filename, size);
|
auto bytes = read_bytes(filename, size);
|
||||||
|
if (bytes == nullptr) {
|
||||||
|
throw std::runtime_error("could not read file " + filename.string());
|
||||||
|
}
|
||||||
return std::string((const char*)bytes.get(), size);
|
return std::string((const char*)bytes.get(), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -266,8 +266,10 @@ static int l_peek(lua::State* L, network::Network& network) {
|
||||||
static int l_available(lua::State* L, network::Network& network) {
|
static int l_available(lua::State* L, network::Network& network) {
|
||||||
u64id_t id = lua::tointeger(L, 1);
|
u64id_t id = lua::tointeger(L, 1);
|
||||||
|
|
||||||
if (auto connection = network.getConnection(id, false)) {
|
if (auto connection = dynamic_cast<network::ReadableConnection*>(
|
||||||
return lua::pushinteger(L, dynamic_cast<network::TcpConnection*>(connection)->available());
|
network.getConnection(id, false)
|
||||||
|
)) {
|
||||||
|
return lua::pushinteger(L, connection->available());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,10 @@ void lua::init_state(State* L, StateType stateType) {
|
||||||
if (stateType == StateType::GENERATOR) {
|
if (stateType == StateType::GENERATOR) {
|
||||||
pushnil(L);
|
pushnil(L);
|
||||||
setglobal(L, "ffi");
|
setglobal(L, "ffi");
|
||||||
|
|
||||||
|
static const char* removed_debug[] {
|
||||||
|
"getregistry", "getupvalue", "setupvalue", "getinfo", nullptr};
|
||||||
|
remove_lib_funcs(L, "debug", removed_debug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,14 @@ public:
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, request.url.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, request.url.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, request.method.c_str());
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, request.method.c_str());
|
||||||
|
|
||||||
|
#if LIBCURL_VERSION_NUM >= 0x075500
|
||||||
|
curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "http,https");
|
||||||
|
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https");
|
||||||
|
#else
|
||||||
|
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||||
|
#endif
|
||||||
|
|
||||||
curl_slist* hs = nullptr;
|
curl_slist* hs = nullptr;
|
||||||
|
|
||||||
for (const auto& header : request.headers) {
|
for (const auto& header : request.headers) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue