From 9eb118eea7396cb33b37de0d993091cfab0bf3c5 Mon Sep 17 00:00:00 2001 From: Sam Leonard Date: Tue, 27 Feb 2024 15:08:37 +0000 Subject: [PATCH] shared/ptyfwd: allow window title but not background color as a valid state Previously if a PTYForward instance had the window title set but no background color set then it would crash in an assertion as pty_forward_ansi_process didn't require both to be present. systemd-vmspawn could get into this state if it failed to get the terminal tint color. Now any method that would have called background_color_sequence now becomes just a NOP if the background color is not set. This allows keeping the functionality to set window titles even if the terminal doesn't support the background coloring. --- src/shared/ptyfwd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index f910f3aaf91..bf775425e78 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -270,7 +270,9 @@ static int insert_newline_color_erase(PTYForward *f, size_t offset) { _cleanup_free_ char *s = NULL; assert(f); - assert(f->background_color); + + if (!f->background_color) + return 0; /* When we see a newline (ASCII 10) then this sets the background color to the desired one, and erase the rest * of the line with it */ @@ -289,7 +291,9 @@ static int insert_carriage_return_color(PTYForward *f, size_t offset) { _cleanup_free_ char *s = NULL; assert(f); - assert(f->background_color); + + if (!f->background_color) + return 0; /* When we see a carriage return (ASCII 13) this this sets only the background */ -- 2.39.2