Skip to content

Commit

Permalink
[core] Restrict FS codebase access to only inside the codebase root d…
Browse files Browse the repository at this point in the history
…irectory
  • Loading branch information
pajama-coder committed Aug 21, 2023
1 parent 7174a3c commit c5c03c4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/codebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ auto CodebaseFromFS::get(const std::string &path) -> SharedData* {
return SharedData::make(buf)->retain();
} else {
std::vector<uint8_t> data;
auto full_path = utils::path_join(m_base, path);
auto norm_path = utils::path_normalize(path);
auto full_path = utils::path_join(m_base, norm_path);
if (!fs::is_file(full_path)) return nullptr;
if (!fs::read_file(full_path, data)) return nullptr;
Data buf(&data[0], data.size(), &s_dp);
Expand All @@ -149,7 +150,8 @@ void CodebaseFromFS::set(const std::string &path, SharedData *data) {
}
}
}
auto full_path = utils::path_join(m_base, path);
auto norm_path = utils::path_normalize(path);
auto full_path = utils::path_join(m_base, norm_path);
std::ofstream fs(full_path, std::ios::out | std::ios::trunc);
if (!fs.is_open()) return;
Data buf(*data);
Expand Down

0 comments on commit c5c03c4

Please sign in to comment.