Skip to content

Commit ad54136

Browse files
comm: check if the input file is a directory after opening it
This prevents a potential race condition where the path could be swapped with a directory in between the `is_dir()` check and the `open()` call.
1 parent 514291d commit ad54136

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/uu/comm/src/comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ fn open_file(name: &OsString, line_ending: LineEnding) -> io::Result<LineReader>
285285
if name == "-" {
286286
Ok(LineReader::new(Input::Stdin(stdin()), line_ending))
287287
} else {
288-
if metadata(name)?.is_dir() {
288+
let f = File::open(name)?;
289+
if f.metadata()?.is_dir() {
289290
return Err(io::Error::other(translate!("comm-error-is-directory")));
290291
}
291-
let f = File::open(name)?;
292292
Ok(LineReader::new(
293293
Input::FileIn(BufReader::new(f)),
294294
line_ending,

0 commit comments

Comments
 (0)