Skip to content

Commit 6f5932f

Browse files
authored
Add protection/workaround for every possible call to fs::absolute with empty path. (openscad#5416)
1 parent fd3a9aa commit 6f5932f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/FontCache.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ FontCache::FontCache()
130130
// For system installs and dev environments, we leave this alone
131131
fs::path fontdir(PlatformUtils::resourcePath("fonts"));
132132
if (fs::is_regular_file(fontdir / "fonts.conf")) {
133-
PlatformUtils::setenv("FONTCONFIG_PATH", (fs::absolute(fontdir).generic_string()).c_str(), 0);
133+
auto abspath = fontdir.empty() ? fs::current_path() : fs::absolute(fontdir);
134+
PlatformUtils::setenv("FONTCONFIG_PATH", (abspath.generic_string()).c_str(), 0);
134135
}
135136

136137
// Just load the configs. We'll build the fonts once all configs are loaded

src/core/parsersettings.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,18 @@ void parser_init()
148148
std::string sep = PlatformUtils::pathSeparatorChar();
149149
using string_split_iterator = boost::split_iterator<std::string::iterator>;
150150
for (string_split_iterator it = boost::make_split_iterator(paths, boost::first_finder(sep, boost::is_iequal())); it != string_split_iterator(); ++it) {
151-
add_librarydir(fs::absolute(fs::path(boost::copy_range<std::string>(*it))).generic_string());
151+
auto str{boost::copy_range<std::string>(*it)};
152+
fs::path abspath = str.empty() ? fs::current_path() : fs::absolute(fs::path(str));
153+
add_librarydir(abspath.generic_string());
152154
}
153155
}
154156

155157
add_librarydir(PlatformUtils::userLibraryPath());
156158

157-
add_librarydir(fs::absolute(PlatformUtils::resourcePath("libraries")).string());
159+
fs::path libpath = PlatformUtils::resourcePath("libraries");
160+
// std::filesystem::absolute() will throw if passed empty path
161+
if (libpath.empty()) {
162+
libpath = fs::current_path();
163+
}
164+
add_librarydir(fs::absolute(libpath).string());
158165
}

src/openscad.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ struct CommandLine
329329
int do_export(const CommandLine& cmd, const RenderVariables& render_variables, FileFormat export_format, SourceFile *root_file)
330330
{
331331
auto filename_str = fs::path(cmd.output_file).generic_string();
332-
auto fpath = fs::absolute(fs::path(cmd.filename));
332+
// Avoid possibility of fs::absolute throwing when passed an empty path
333+
auto fpath = cmd.filename.empty() ? fs::current_path() : fs::absolute(fs::path(cmd.filename));
333334
auto fparent = fpath.parent_path();
334335

335336
// set CWD relative to source file

0 commit comments

Comments
 (0)