From d523e7a676d6d2cdda0369fac3dc9f953d3a4e96 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 17 Dec 2024 11:01:17 +0100 Subject: term: set_app_id() + set_window_title(): only allow printable characters --- misc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index 1e5b9328..c7abe03b 100644 --- a/misc.c +++ b/misc.c @@ -44,8 +44,19 @@ timespec_sub(const struct timespec *a, const struct timespec *b, } bool -is_valid_utf8(const char *value) +is_valid_utf8_and_printable(const char *value) { - return value != NULL && - mbsntoc32(NULL, value, strlen(value), 0) != (size_t)-1; + char32_t *wide = ambstoc32(value); + if (wide == NULL) + return false; + + for (const char32_t *c = wide; *c != U'\0'; c++) { + if (!isc32print(*c)) { + free(wide); + return false; + } + } + + free(wide); + return true; } -- cgit v1.3