mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
tail: fix TOCTOU race in follow retry logic
* Replace exists() check followed by metadata().unwrap() with a single if-let on metadata(). The file could be removed between the two calls, causing a panic with "No such file or directory" (seen intermittently in test_retry9).
This commit is contained in:
@@ -506,9 +506,10 @@ pub fn follow(mut observer: Observer, settings: &Settings) -> UResult<()> {
|
||||
// here paths will not be removed from orphans if the path becomes available.
|
||||
if observer.follow_name_retry() {
|
||||
for new_path in &observer.orphans {
|
||||
if new_path.exists() {
|
||||
// Use metadata() directly instead of exists() + metadata().unwrap()
|
||||
// to avoid a TOCTOU race where the file is removed between the two calls.
|
||||
if let Ok(md) = new_path.metadata() {
|
||||
let pd = observer.files.get(new_path);
|
||||
let md = new_path.metadata().unwrap();
|
||||
if md.is_tailable() && pd.reader.is_none() {
|
||||
show_error!(
|
||||
"{}",
|
||||
|
||||
Reference in New Issue
Block a user