diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index 1f2547ac9..13e1b86e0 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -238,11 +238,13 @@ namespace hex::plugin::builtin::prv { #else const auto &path = this->m_path.native(); + int mmapprot = PROT_READ | PROT_WRITE; this->m_file = ::open(path.c_str(), O_RDWR); if (this->m_file == -1) { this->m_file = ::open(path.c_str(), O_RDONLY); this->m_writable = false; + mmapprot &= ~(PROT_WRITE); } if (this->m_file == -1) { @@ -252,8 +254,8 @@ namespace hex::plugin::builtin::prv { this->m_fileSize = this->m_fileStats.st_size; - this->m_mappedFile = ::mmap(nullptr, this->m_fileSize, PROT_READ | PROT_WRITE, MAP_SHARED, this->m_file, 0); - if (this->m_mappedFile == nullptr) { + this->m_mappedFile = ::mmap(nullptr, this->m_fileSize, mmapprot, MAP_SHARED, this->m_file, 0); + if (this->m_mappedFile == MAP_FAILED) { ::close(this->m_file); this->m_file = -1;