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 87d6f2c..e728cec 100644 --- a/src/screen.c +++ b/src/screen.c @@ -841,12 +841,26 @@ 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(); static const struct term_options defaults; if (!opt) opt = &defaults; + const char *name = opt->name && *opt->name ? opt->name : "term"; + if (!name_valid(name)) + return NULL; int cols = opt->size.x < 1 ? 80 : opt->size.x; int rows = opt->size.y < 1 ? 24 : opt->size.y; if (cols > TERM_MAX_COLS) @@ -856,6 +870,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; @@ -902,7 +917,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)); |
