mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
term: set_app_id() + set_window_title(): only allow printable characters
This commit is contained in:
parent
9a1b59adae
commit
d523e7a676
4 changed files with 19 additions and 6 deletions
|
|
@ -74,6 +74,8 @@
|
|||
* Use `utf8proc_charwidth()` instead of `wcwidth()`+`wcswidth()` when
|
||||
calculating character width, when foot has been built with utf8proc
|
||||
support ([#1865][1865]).
|
||||
* Run-time changes to the window title, and the app ID now require the
|
||||
new value to consist of printable characters only.
|
||||
|
||||
[1865]: https://codeberg.org/dnkl/foot/issues/1865
|
||||
|
||||
|
|
|
|||
17
misc.c
17
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;
|
||||
}
|
||||
|
|
|
|||
2
misc.h
2
misc.h
|
|
@ -9,4 +9,4 @@ bool isword(char32_t wc, bool spaces_only, const char32_t *delimiters);
|
|||
void timespec_add(const struct timespec *a, const struct timespec *b, struct timespec *res);
|
||||
void timespec_sub(const struct timespec *a, const struct timespec *b, struct timespec *res);
|
||||
|
||||
bool is_valid_utf8(const char *value);
|
||||
bool is_valid_utf8_and_printable(const char *value);
|
||||
|
|
|
|||
|
|
@ -3570,7 +3570,7 @@ term_set_window_title(struct terminal *term, const char *title)
|
|||
if (term->window_title != NULL && streq(term->window_title, title))
|
||||
return;
|
||||
|
||||
if (!is_valid_utf8(title)) {
|
||||
if (!is_valid_utf8_and_printable(title)) {
|
||||
/* It's an xdg_toplevel::set_title() protocol violation to set
|
||||
a title with an invalid UTF-8 sequence */
|
||||
LOG_WARN("%s: title is not valid UTF-8, ignoring", title);
|
||||
|
|
@ -3593,7 +3593,7 @@ term_set_app_id(struct terminal *term, const char *app_id)
|
|||
if (term->app_id != NULL && app_id != NULL && streq(term->app_id, app_id))
|
||||
return;
|
||||
|
||||
if (app_id != NULL && !is_valid_utf8(app_id)) {
|
||||
if (app_id != NULL && !is_valid_utf8_and_printable(app_id)) {
|
||||
LOG_WARN("%s: app-id is not valid UTF-8, ignoring", app_id);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue