Skip to content

Commit ae175e6

Browse files
committed
fix(build): avoid filesystem path iteration
1 parent 1593afe commit ae175e6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/cli.cppm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,21 @@ materialize_generated_files(const std::filesystem::path& root,
645645
return std::unexpected(std::format(
646646
"generated_files path '{}' must be relative", relPath.generic_string()));
647647
}
648-
for (auto const& part : relPath) {
648+
auto const genericPath = relPath.generic_string();
649+
for (std::size_t begin = 0; begin <= genericPath.size();) {
650+
auto const end = genericPath.find('/', begin);
651+
auto const part = genericPath.substr(begin, end == std::string::npos
652+
? std::string::npos
653+
: end - begin);
649654
if (part == "..") {
650655
return std::unexpected(std::format(
651656
"generated_files path '{}' must not escape the package root",
652657
relPath.generic_string()));
653658
}
659+
if (end == std::string::npos) {
660+
break;
661+
}
662+
begin = end + 1;
654663
}
655664

656665
auto out = root / relPath.lexically_normal();

0 commit comments

Comments
 (0)