Skip to content

Fix single component paths in disk space checks #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,15 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
sec->writeHeaderTo<ELFT>(++sHdrs);
}

static StringRef parentPathOrDot(StringRef path) {
auto parent_path = sys::path::parent_path(path);
if (parent_path.empty() && !path.empty() && !sys::path::is_absolute(path)) {
return ".";
} else {
return parent_path;
}
}

// Open a result file.
template <class ELFT> void Writer<ELFT>::openFile() {
uint64_t maxSize = config->is64 ? INT64_MAX : UINT32_MAX;
Expand All @@ -2825,7 +2834,7 @@ template <class ELFT> void Writer<ELFT>::openFile() {
// In case there's no space left on the device
// it will error with SIGBUS, which is confusing
// for users
auto ErrOrSpaceInfo = sys::fs::disk_space(sys::path::parent_path(config->outputFile));
auto ErrOrSpaceInfo = sys::fs::disk_space(parentPathOrDot(config->outputFile));
if (!ErrOrSpaceInfo)
error("Can't get remaining size on disk");
if (ErrOrSpaceInfo.get().free < fileSize)
Expand Down