mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-03 13:20:25 -05:00
fix: make the preload helper correct on FreeBSD and safe on reopen
- The helper called Linux fgetxattr on FreeBSD. Read mergerfs.fullpath there through extattr_get_fd in EXTATTR_NAMESPACE_USER; Linux keeps user.mergerfs.fullpath. - FreeBSD mode_t is promoted when passed through an ellipsis, so reading it back as mode_t was undefined. Read the promoted type. - O_TMPFILE includes O_DIRECTORY on Linux, so a plain directory open consumed a mode argument that wasn't passed. Require O_CREAT or the whole nonzero O_TMPFILE mask. - The backing path is returned without a terminating NUL. Reject empty or oversized values and terminate it before reopening; keep the already-open descriptor when no usable path is available. - The reopen of the backing file repeated O_TRUNC, and creat() ran creat() again. The open through mergerfs had already truncated that file, so the second truncation could only destroy data another process wrote in between. Drop O_TRUNC from the reopen and reopen creat()ed files O_WRONLY. - fopen and fopen64 reopened the branch path with the caller's mode, so w truncated a second time and a could recreate a name removed in between. Redirect only modes starting with r, including r+, as given, and keep the original stream otherwise; tooling.md says so. TEST_preload_fopen_modes checks the bytes and that a missing branch name is not created. - fs_fstatat.hpp used AT_SYMLINK_NOFOLLOW without including fcntl.h, which failed against FreeBSD headers.
This commit is contained in:
parent
eea1c1bc09
commit
11e759101d
4 changed files with 195 additions and 90 deletions
|
|
@ -21,6 +21,7 @@
|
|||
#include "fs_path.hpp"
|
||||
#include "to_neg_errno.hpp"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue