Skip to content

Commit

Permalink
Add protection/workaround for every possible call to fs::absolute wit…
Browse files Browse the repository at this point in the history
…h empty path. (openscad#5416)
  • Loading branch information
thehans authored Nov 10, 2024
1 parent fd3a9aa commit 6f5932f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/FontCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ FontCache::FontCache()
// For system installs and dev environments, we leave this alone
fs::path fontdir(PlatformUtils::resourcePath("fonts"));
if (fs::is_regular_file(fontdir / "fonts.conf")) {
PlatformUtils::setenv("FONTCONFIG_PATH", (fs::absolute(fontdir).generic_string()).c_str(), 0);
auto abspath = fontdir.empty() ? fs::current_path() : fs::absolute(fontdir);
PlatformUtils::setenv("FONTCONFIG_PATH", (abspath.generic_string()).c_str(), 0);
}

// Just load the configs. We'll build the fonts once all configs are loaded
Expand Down
11 changes: 9 additions & 2 deletions src/core/parsersettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,18 @@ void parser_init()
std::string sep = PlatformUtils::pathSeparatorChar();
using string_split_iterator = boost::split_iterator<std::string::iterator>;
for (string_split_iterator it = boost::make_split_iterator(paths, boost::first_finder(sep, boost::is_iequal())); it != string_split_iterator(); ++it) {
add_librarydir(fs::absolute(fs::path(boost::copy_range<std::string>(*it))).generic_string());
auto str{boost::copy_range<std::string>(*it)};
fs::path abspath = str.empty() ? fs::current_path() : fs::absolute(fs::path(str));
add_librarydir(abspath.generic_string());
}
}

add_librarydir(PlatformUtils::userLibraryPath());

add_librarydir(fs::absolute(PlatformUtils::resourcePath("libraries")).string());
fs::path libpath = PlatformUtils::resourcePath("libraries");
// std::filesystem::absolute() will throw if passed empty path
if (libpath.empty()) {
libpath = fs::current_path();
}
add_librarydir(fs::absolute(libpath).string());
}
3 changes: 2 additions & 1 deletion src/openscad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ struct CommandLine
int do_export(const CommandLine& cmd, const RenderVariables& render_variables, FileFormat export_format, SourceFile *root_file)
{
auto filename_str = fs::path(cmd.output_file).generic_string();
auto fpath = fs::absolute(fs::path(cmd.filename));
// Avoid possibility of fs::absolute throwing when passed an empty path
auto fpath = cmd.filename.empty() ? fs::current_path() : fs::absolute(fs::path(cmd.filename));
auto fparent = fpath.parent_path();

// set CWD relative to source file
Expand Down

0 comments on commit 6f5932f

Please sign in to comment.