Make fish_indent stop panicing on closed stdin

Prior to this commit, this code:

    fish_indent <&-

would panic as we would construct a File with a negative fd.
Check for a closed fd as other builtins do.
This commit is contained in:
Peter Ammon
2025-12-30 12:33:33 -08:00
parent eb803ba6a7
commit 4101e831af
2 changed files with 11 additions and 0 deletions

View File

@@ -1042,6 +1042,13 @@ enum OutputType {
));
return Err(STATUS_CMD_ERROR);
}
if streams.stdin_fd < 0 {
let cmd = "fish_indent";
streams
.err
.append(&wgettext_fmt!("%s: stdin is closed\n", cmd));
return Err(STATUS_CMD_ERROR);
}
use std::os::fd::FromRawFd;
let mut fd = unsafe { std::fs::File::from_raw_fd(streams.stdin_fd) };
let mut buf = vec![];

View File

@@ -652,3 +652,7 @@ cat $tmpdir/indent_test.fish
# See that the builtin can be redirected
printf %s\n a b c | builtin fish_indent | grep b
# CHECK: b
# Regression test that fish_indent doesn't panic with closed stdin.
fish_indent <&-
# CHECKERR: fish_indent: stdin is closed