Skip to content

Commit e811787

Browse files
committed
🐛 fix(rm): reject directory as pathspec-from-file argument
1 parent 0917bd4 commit e811787

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • crates/git-command/src

‎crates/git-command/src/rm.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,20 @@ fn read_pathspec_file(
360360
let mut input: Box<dyn BufRead> = if file == "-" {
361361
Box::new(std::io::stdin().lock())
362362
} else {
363-
let input = std::fs::File::open(ctx.cwd.join(file)).map_err(|e| {
363+
let full = ctx.cwd.join(file);
364+
let input = std::fs::File::open(&full).map_err(|e| {
364365
CommandError::fatal(format!(
365366
"fatal: could not open '{file}' for reading: {}",
366367
io_strerror(&e)
367368
))
368369
})?;
370+
// `xfopen` fails on directories (EISDIR); `File::open` succeeds on
371+
// them and yields an empty stream, which C treats as "no pathspec".
372+
if input.metadata().map(|m| m.is_dir()).unwrap_or(false) {
373+
return Err(CommandError::fatal(format!(
374+
"fatal: could not open '{file}' for reading: Is a directory"
375+
)));
376+
}
369377
Box::new(BufReader::new(input))
370378
};
371379
let delimiter = if nul { 0 } else { b'\n' };

0 commit comments

Comments
 (0)