fix(file): create implicit directories with 0777 & ~umask (rsync parity)
CI / lint (pull_request) Successful in 1m58s
CI / sanitizers (address) (pull_request) Skipped
CI / sanitizers (undefined) (pull_request) Skipped
CI / fuzz-build (pull_request) Skipped
CI / coverage (pull_request) Skipped
CI / valgrind (pull_request) Skipped
CI / build-and-test (pull_request) Successful in 45s
CI / lint (pull_request) Successful in 1m58s
CI / sanitizers (address) (pull_request) Skipped
CI / sanitizers (undefined) (pull_request) Skipped
CI / fuzz-build (pull_request) Skipped
CI / coverage (pull_request) Skipped
CI / valgrind (pull_request) Skipped
CI / build-and-test (pull_request) Successful in 45s
Implicit parent directories were created with a hardcoded 0755, diverging from rsync's 0777 & ~umask whenever the process umask is not 022 (the CI runner uses 0). Matches rsync under any umask; verified with umask 0.
This commit is contained in:
+2
-2
@@ -671,7 +671,7 @@ int file_open_secure_parent(const char* path, char** leaf_out, bool create_dirs)
|
|||||||
if (strcmp(component, ".") != 0) {
|
if (strcmp(component, ".") != 0) {
|
||||||
int next = openat(fd, component, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
int next = openat(fd, component, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
||||||
if (next < 0 && create_dirs && errno == ENOENT) {
|
if (next < 0 && create_dirs && errno == ENOENT) {
|
||||||
bool created = mkdirat(fd, component, 0755) == 0;
|
bool created = mkdirat(fd, component, (mode_t)(0777 & ~(mode_t)file_process_umask())) == 0;
|
||||||
if (created || errno == EEXIST) {
|
if (created || errno == EEXIST) {
|
||||||
/* P7 Wave E: --copy-as owns EVERY entry, including the intermediate
|
/* P7 Wave E: --copy-as owns EVERY entry, including the intermediate
|
||||||
directories this walk creates implicitly. Its target ids are a
|
directories this walk creates implicitly. Its target ids are a
|
||||||
@@ -800,7 +800,7 @@ bool file_ensure_directory_secure(const char* path) {
|
|||||||
int dir_fd = openat(parent_fd, leaf, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
int dir_fd = openat(parent_fd, leaf, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
||||||
bool created = false;
|
bool created = false;
|
||||||
if (dir_fd < 0 && errno == ENOENT) {
|
if (dir_fd < 0 && errno == ENOENT) {
|
||||||
if (mkdirat(parent_fd, leaf, 0755) == 0) {
|
if (mkdirat(parent_fd, leaf, (mode_t)(0777 & ~(mode_t)file_process_umask())) == 0) {
|
||||||
created = true;
|
created = true;
|
||||||
dir_fd = openat(parent_fd, leaf, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
dir_fd = openat(parent_fd, leaf, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
||||||
} else if (errno == EEXIST) {
|
} else if (errno == EEXIST) {
|
||||||
|
|||||||
Reference in New Issue
Block a user