From 4101e831afb406f675ba4cac4f8d62596ebc90a7 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Tue, 30 Dec 2025 12:33:33 -0800 Subject: [PATCH] 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. --- src/builtins/fish_indent.rs | 7 +++++++ tests/checks/indent.fish | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/builtins/fish_indent.rs b/src/builtins/fish_indent.rs index 9afc87f9b..3e707a722 100644 --- a/src/builtins/fish_indent.rs +++ b/src/builtins/fish_indent.rs @@ -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![]; diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index 05491c861..1881d6b12 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -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