From bd9c6a64e39a2d1650c0040e4b03ab04915882e8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Apr 2022 13:25:38 -0700 Subject: [PATCH] Be careful to not touch curses variables if cur_term is null Curses variables like `enter_italics_mode` are secretly defined to dereference through the `cur_term` variable. Be sure we do not read or write these curses variables if cur_term is NULL. See #8873, #8875. Add a regression test. --- src/env_dispatch.cpp | 5 +++++ tests/pexpects/nullterm.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/pexpects/nullterm.py diff --git a/src/env_dispatch.cpp b/src/env_dispatch.cpp index 588dc90ee..f989dbe6c 100644 --- a/src/env_dispatch.cpp +++ b/src/env_dispatch.cpp @@ -491,6 +491,11 @@ static void initialize_curses_using_fallbacks(const environment_t &vars) { // Apply any platform-specific hacks to cur_term/ static void apply_term_hacks(const environment_t &vars) { UNUSED(vars); + // Be careful, variables like "enter_italics_mode" are #defined to dereference through cur_term. + // See #8876. + if (!cur_term) { + return; + } #ifdef __APPLE__ // Hack in missing italics and dim capabilities omitted from MacOS xterm-256color terminfo // Helps Terminal.app/iTerm diff --git a/tests/pexpects/nullterm.py b/tests/pexpects/nullterm.py new file mode 100644 index 000000000..1e87386d2 --- /dev/null +++ b/tests/pexpects/nullterm.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +import os +from pexpect_helper import SpawnedProc + +# Regression test for #8873. +# fish doesn't crash if TERM is unset. +env = os.environ.copy() +env.pop("TERM", None) + +sp = SpawnedProc(env=env) +sendline, expect_prompt = sp.sendline, sp.expect_prompt + +expect_prompt() +sendline("set_color --italics") +expect_prompt() +sendline("set_color normal") +expect_prompt()