Skip to content

Commit b6cf570

Browse files
committed
fix: eliminate TOCTOU races in ln and tac by deferring is_dir() checks
ln: call hard_link() first, check is_dir() only on failure for diagnostics tac: remove is_dir()/metadata() pre-checks, open file directly and let OS report errors (EISDIR, ENOENT) Closes #9450
1 parent 399118e commit b6cf570

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/uu/tac/src/tac.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ use memchr::memmem;
1212
use memmap2::Mmap;
1313
use std::ffi::{OsStr, OsString};
1414
use std::io::{BufWriter, Read, Write, stdin, stdout};
15-
use std::{
16-
fs::File,
17-
io::copy,
18-
path::Path,
19-
};
20-
15+
use std::{fs::File, io::copy, path::Path};
16+
#[cfg(unix)]
17+
use uucore::error::UError;
18+
use uucore::error::UResult;
2119
#[cfg(unix)]
2220
use uucore::error::set_exit_code;
23-
use uucore::error::{UError, UResult};
2421
use uucore::{format_usage, show};
2522

2623
use crate::error::TacError;

0 commit comments

Comments
 (0)