From ebb733bad012cfeb1950f56842f54f2472c22fa3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 24 Nov 2024 09:06:46 +0530 Subject: [PATCH] Wayland: Pass valid UTF-8 as title When stripping CSI sequences from the title, dont mutilate interleaved multi-byte UTF-8 sequences. Fixes #8067 --- docs/changelog.rst | 2 ++ kitty/glfw.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f688204e2..2e6093cdc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -95,6 +95,8 @@ Detailed list of changes - clipboard kitten: Fix a bug causing kitten to hang in filter mode when input data size is not divisible by 3 and larger than 8KB (:iss:`8059`) +- Wayland: Fix an abort when a client program tries to set an invalid title containing interleaved escape codes and UTF-8 multi-byte characters (:iss:`8067`) + 0.37.0 [2024-10-30] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/glfw.c b/kitty/glfw.c index 01911e630..c3cca60b6 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -8,6 +8,7 @@ #include "cleanup.h" #include "monotonic.h" #include "charsets.h" +#include "control-codes.h" #include #include "glfw-wrapper.h" #include "gl.h" @@ -71,7 +72,7 @@ strip_csi_(const char *title, char *buf, size_t bufsz) { *dest = 0; *last = 0; for (; *title && dest < last; title++) { - const char ch = *title; + const unsigned char ch = *title; switch (state) { case NORMAL: { if (ch == 0x1b) { state = IN_ESC; } @@ -79,10 +80,16 @@ strip_csi_(const char *title, char *buf, size_t bufsz) { } break; case IN_ESC: { if (ch == '[') { state = IN_CSI; } - else { state = NORMAL; } + else { + if (ch >= ' ' && ch != DEL) *(dest++) = ch; + state = NORMAL; + } } break; case IN_CSI: { - if (!(('0' <= ch && ch <= '9') || ch == ';' || ch == ':')) state = NORMAL; + if (!(('0' <= ch && ch <= '9') || ch == ';' || ch == ':')) { + if (ch >= ' ' && ch != DEL) *(dest++) = ch; + state = NORMAL; + } } break; } }