From 7ed78a31debb0250bae16d8b4098a4689f29bb60 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 12:30:14 +0300 Subject: Take the terminal name from term_options.name The core hard-coded "wsap_term" for XTVERSION, the XTGETTCAP TN and name default, and the OSC 9 notification title. A headless library should take its identity from the host. term_options.name sets the name. NULL or "" selects "term". term_new() copies it and returns NULL unless it is 1 to 63 printable ASCII bytes, since DCS replies echo it. A DCS +p still changes the TN value, and the XTVERSION and notification defaults keep the host name. Co-Authored-By: Claude Haiku 5.5 --- tests/term_test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/term_test.c') diff --git a/tests/term_test.c b/tests/term_test.c index 66dbd96..e4ffb27 100644 --- a/tests/term_test.c +++ b/tests/term_test.c @@ -1485,6 +1485,32 @@ static void test_string_payloads(void) } } +/* term_new() refuses a name that a DCS reply could echo unsafely. */ +static void test_host_name_rejected(void) +{ + static const char *const bad[] = { + "\033x", "a\tb", "\177", "\300", "a\nb", + }; + char longest[65]; + memset(longest, 'a', 64); + longest[64] = 0; + char fits[64]; + memset(fits, 'b', 63); + fits[63] = 0; + + for (size_t i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) { + struct term_options opt = { .size = { .x = 10, .y = 3 }, .name = bad[i] }; + assert(!term_new(&opt)); + } + struct term_options opt = { .size = { .x = 10, .y = 3 }, .name = longest }; + assert(!term_new(&opt)); + + opt.name = fits; + struct term *t = term_new(&opt); + assert(t); + term_free(t); +} + static void test_newline_policy_survives_reset(void) { static const char *const resets[] = { "\033c", "\033[!p", "\033[20l" }; @@ -1860,6 +1886,7 @@ int main(void) test_alt_erase_scrollback(); test_snapshot_follows_new_terminal(); test_bulk_rows_survive_edits(); + test_host_name_rejected(); assert(!strcmp(UNICODE_DATA_VERSION, "18.0.0")); assert(!strcmp(term_unicode_version(), UNICODE_DATA_VERSION)); -- cgit v1.2.3