[llvm-bugs] [Bug 49493] New: std::filesystem::weakly_canonical race condition when the underlying path is removed
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Mar 9 10:08:15 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49493
Bug ID: 49493
Summary: std::filesystem::weakly_canonical race condition when
the underlying path is removed
Product: libc++
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: xavier.roche at algolia.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
Created attachment 24609
--> https://bugs.llvm.org/attachment.cgi?id=24609&action=edit
Test aimed to reproduce the race issue
The std::filesystem::weakly_canonical function is normally able to canonize
both non-existing path(es) and existing path(es).
However, the current implementation is having issues with canonizing a path
that disappears while the function is being called, leading to randomly
returning errors (and/or raising filesystem_error).
Important Note: this MAY be an expected behavior, as the official specification
of std::filesystem::weakly_canonical does not appear to be completely clear
towards impact of filesystem volatility.
The attached sample demonstrate the issue:
-----------------------------------------
clang++ -g3 -pthread -std=c++20 filesystem_weakly_canonical-race-canonical.cpp
-o filesystem_weakly_canonical-race-canonical
./filesystem_weakly_canonical-race-canonical
Starting computing
terminate called after throwing an instance of
'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: cannot make canonical path: No such file or
directory [foo]
Aborted (core dumped)
Our understanding is that std::filesystem::weakly_canonical calls
std::filesystem::canonical under the hood, if the path segment exist:
while (PP.State != PathParser::PS_BeforeBegin) {
tmp.assign(createView(p.native().data(), &PP.RawEntry.back()));
error_code m_ec;
file_status st = __status(tmp, &m_ec);
if (!status_known(st)) {
return err.report(m_ec);
} else if (exists(st)) {
result = __canonical(tmp, ec);
break;
}
DNEParts.push_back(*PP);
--PP;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210309/6ff29cca/attachment.html>
More information about the llvm-bugs
mailing list