Skip to content

Commit f4bfb67

Browse files
committed
safe-traversal is always used on linux, adjust the cfg
1 parent 01a176c commit f4bfb67

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/uucore/src/lib/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod pipes;
6767
pub mod proc_info;
6868
#[cfg(all(unix, feature = "process"))]
6969
pub mod process;
70-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
70+
#[cfg(target_os = "linux")]
7171
pub mod safe_traversal;
7272
#[cfg(all(target_os = "linux", feature = "tty"))]
7373
pub mod tty;

src/uucore/src/lib/features/perms.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use libc::{gid_t, uid_t};
1818
use options::traverse;
1919
use std::ffi::OsString;
2020

21-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
21+
#[cfg(not(target_os = "linux"))]
2222
use walkdir::WalkDir;
2323

24-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
24+
#[cfg(target_os = "linux")]
2525
use crate::features::safe_traversal::DirFd;
2626

2727
use std::ffi::CString;
@@ -308,7 +308,7 @@ impl ChownExecutor {
308308

309309
let ret = if self.matched(meta.uid(), meta.gid()) {
310310
// Use safe syscalls for root directory to prevent TOCTOU attacks
311-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
311+
#[cfg(target_os = "linux")]
312312
let chown_result = if path.is_dir() {
313313
// For directories, use safe traversal from the start
314314
match DirFd::open(path) {
@@ -331,7 +331,7 @@ impl ChownExecutor {
331331
)
332332
};
333333

334-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
334+
#[cfg(not(target_os = "linux"))]
335335
let chown_result = wrap_chown(
336336
path,
337337
&meta,
@@ -365,11 +365,11 @@ impl ChownExecutor {
365365
};
366366

367367
if self.recursive {
368-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
368+
#[cfg(target_os = "linux")]
369369
{
370370
ret | self.safe_dive_into(&root)
371371
}
372-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
372+
#[cfg(not(target_os = "linux"))]
373373
{
374374
ret | self.dive_into(&root)
375375
}
@@ -378,7 +378,7 @@ impl ChownExecutor {
378378
}
379379
}
380380

381-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
381+
#[cfg(target_os = "linux")]
382382
fn safe_chown_dir(
383383
&self,
384384
dir_fd: &DirFd,
@@ -399,7 +399,7 @@ impl ChownExecutor {
399399
Ok(String::new())
400400
}
401401

402-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
402+
#[cfg(target_os = "linux")]
403403
fn safe_dive_into<P: AsRef<Path>>(&self, root: P) -> i32 {
404404
let root = root.as_ref();
405405

@@ -425,7 +425,7 @@ impl ChownExecutor {
425425
ret
426426
}
427427

428-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
428+
#[cfg(target_os = "linux")]
429429
fn safe_traverse_dir(&self, dir_fd: &DirFd, dir_path: &Path, ret: &mut i32) {
430430
// Read directory entries
431431
let entries = match dir_fd.read_dir() {
@@ -530,7 +530,7 @@ impl ChownExecutor {
530530
}
531531
}
532532

533-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
533+
#[cfg(not(target_os = "linux"))]
534534
#[allow(clippy::cognitive_complexity)]
535535
fn dive_into<P: AsRef<Path>>(&self, root: P) -> i32 {
536536
let root = root.as_ref();
@@ -667,7 +667,7 @@ impl ChownExecutor {
667667
}
668668

669669
/// Try to open directory with error reporting
670-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
670+
#[cfg(target_os = "linux")]
671671
fn try_open_dir(&self, path: &Path) -> Option<DirFd> {
672672
DirFd::open(path)
673673
.map_err(|e| {
@@ -680,7 +680,7 @@ impl ChownExecutor {
680680

681681
/// Report ownership change with proper verbose output
682682
/// Returns 0 on success
683-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
683+
#[cfg(target_os = "linux")]
684684
fn report_ownership_change_success(
685685
&self,
686686
path: &Path,

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// spell-checker:ignore CLOEXEC RDONLY TOCTOU closedir dirp fdopendir fstatat openat REMOVEDIR unlinkat smallfile
1212
// spell-checker:ignore RAII dirfd fchownat fchown FchmodatFlags fchmodat fchmod
1313

14-
#![cfg(target_os = "linux")]
15-
1614
#[cfg(test)]
1715
use std::os::unix::ffi::OsStringExt;
1816

src/uucore/src/lib/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub use crate::features::perms;
9292
pub use crate::features::pipes;
9393
#[cfg(all(unix, feature = "process"))]
9494
pub use crate::features::process;
95-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
95+
#[cfg(target_os = "linux")]
9696
pub use crate::features::safe_traversal;
9797
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))]
9898
pub use crate::features::signals;

0 commit comments

Comments
 (0)