summaryrefslogtreecommitdiff
path: root/src/screen.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 12:38:43 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 12:38:43 +0300
commitcaf7d446446a0af0b30886a6c4ee5851aab553e2 (patch)
tree28cb796f01711d8484bc6cb3daa8e551db18fe68 /src/screen.c
parent6cd9ab6f73994b68e8453c92a014d1a372af2a24 (diff)
parent7ed78a31debb0250bae16d8b4098a4689f29bb60 (diff)
Merge branch 'wt/host-name' into api-hardening
# Conflicts: # src/screen.c
Diffstat (limited to 'src/screen.c')
-rw-r--r--src/screen.c17
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));