diff options
Diffstat (limited to 'src/screen.c')
| -rw-r--r-- | src/screen.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/screen.c b/src/screen.c index ab912a1..0857f17 100644 --- a/src/screen.c +++ b/src/screen.c @@ -840,6 +840,17 @@ bool term_tables_ready(void) return atomic_load_explicit(&tables_state, memory_order_relaxed) == 2; } +/* A name is 1 to 63 printable ASCII bytes. DCS replies echo it. */ +static bool name_valid(const char *s) +{ + for (size_t i = 0; s[i]; i++) { + unsigned char c = (unsigned char)s[i]; + if (i >= 63 || c < 0x20 || c > 0x7e) + return false; + } + return true; +} + struct term *term_new(const struct term_options *opt) { tables_init(); @@ -853,6 +864,9 @@ struct term *term_new(const struct term_options *opt) return NULL; if (opt->scrollback < 0 || (unsigned)opt->cursor_style > TERM_CURSOR_BAR) return NULL; + const char *name = opt->name && *opt->name ? opt->name : "term"; + if (!name_valid(name)) + return NULL; int cols = opt->size.x == 0 ? 80 : opt->size.x; int rows = opt->size.y == 0 ? 24 : opt->size.y; @@ -860,6 +874,7 @@ struct term *term_new(const struct term_options *opt) struct term *t = calloc(1, sizeof(*t)); if (!t) return NULL; + memcpy(t->name, name, strlen(name) + 1); atomic_init(&t->seq, 0); atomic_init(&t->writer_tid, 0); t->write_depth = 0; @@ -906,7 +921,7 @@ struct term *term_new(const struct term_options *opt) t->autowrap = true; t->charsets[0] = t->charsets[1] = 'B'; t->saved = term_saved_cursor_initial(); - memcpy(t->tcap_name, "wsap_term", sizeof("wsap_term")); + memcpy(t->tcap_name, t->name, sizeof(t->name)); term_tabs_default(t); t->full_gen = 1; memset(t->text_width.lo, 0xFF, sizeof(t->text_width.lo)); |
