Explicitly close input fd to fish_title

`fish_title` as invoked by fish itself is not running in an interactive
context, and attempts to read from the input fd (e.g. via `read`) cause
fish to segfault, go into an infinite loop, or hang at the read prompt
depending on the exact command line and fish version.

This patch addresses that by explicitly closing the input fd when
invoking `fish_title`.

Reported by @floam in #5629. May close that issue, but situation is
unclear.
This commit is contained in:
Mahmoud Al-Qudsi 2019-02-12 19:43:09 -06:00
parent 717718353e
commit b247c8d9ad

View File

@ -829,6 +829,12 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) {
fish_title_command.append(
escape_string(cmd, ESCAPE_ALL | ESCAPE_NO_QUOTED | ESCAPE_NO_TILDE));
}
// `fish_title` is executed in a non-interactive context and attempts at reading
// from within that function will cause problems ranging segfaults, SIGTTIN
// deadlocks, or infinite loops - we explicitly close the input fd to safeguard
// against such a scenario.
fish_title_command.append(L"<&-");
}
wcstring_list_t lst;