This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-12-session-parity
in repository terminology.
View the commit online.
commit dd42fbe119644f657d00d97772b07b0f13afc562
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 22 17:29:04 2026 -0600
termio: ignore edje channel commands for unknown blocks
An `ix` escape naming an unknown channel dereferenced a NULL block, so
program output could crash the terminal. Freed blocks also stayed in
the channel map, leaving `ix` and `iC` a dangling pointer.
A block now leaves the map when it is freed, unless a newer block has
claimed its channel. The newest block wins a channel: an older one
that lost it stops receiving channel commands.
---
DESIGN.md | 1 +
src/bin/meson.build | 5 ++++
src/bin/termio.c | 6 +++--
src/bin/termpty.c | 14 +++-------
src/bin/termpty.h | 1 -
src/bin/termptyblock.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/bin/termptyblock.h | 8 ++++++
src/bin/tytest.c | 2 ++
src/bin/unit_tests.h | 2 ++
9 files changed, 98 insertions(+), 13 deletions(-)
diff --git a/DESIGN.md b/DESIGN.md
index 6ea9658d..dc22292b 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -33,6 +33,7 @@ A simple documentation to navigate through the C files:
* `src/bin/termio.c`: the core term widget with the textgrid
* `src/bin/termiolink.c`: link detection in the terminal
* `src/bin/termpty.c`: the PTY interaction
+* `src/bin/termptyblock.c`: parses and looks up media blocks for a Termpty
* `src/bin/termptydbl.c`: code to hande double-width characters
* `src/bin/termptyesc.c`: escape codes parsing
* `src/bin/termptyext.c`: extented terminology escape handling
diff --git a/src/bin/meson.build b/src/bin/meson.build
index bae139c9..653c1ff8 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -51,6 +51,7 @@ terminology_sources = ['private.h',
'termiointernals.c', 'termiointernals.h',
'termiolink.c', 'termiolink.h',
'termpty.c', 'termpty.h',
+ 'termptyblock.c', 'termptyblock.h',
'termptydbl.c', 'termptydbl.h',
'termptytcap.h',
'termptyesc.c', 'termptyesc.h',
@@ -102,6 +103,7 @@ tyfuzz_sources = [color_names,
'termptyext.c', 'termptyext.h',
'termptygfx.c', 'termptygfx.h',
'termpty.c', 'termpty.h',
+ 'termptyblock.c', 'termptyblock.h',
'termiointernals.c', 'termiointernals.h',
'termiolink.c', 'termiolink.h',
'config.c', 'config.h',
@@ -128,6 +130,7 @@ tytest_sources = [color_names,
'termptyext.c', 'termptyext.h',
'termptygfx.c', 'termptygfx.h',
'termpty.c', 'termpty.h',
+ 'termptyblock.c', 'termptyblock.h',
'termiointernals.c', 'termiointernals.h',
'termiolink.c', 'termiolink.h',
'config.c', 'config.h',
@@ -164,6 +167,7 @@ tybench_sources = [color_names,
'termptyext.c', 'termptyext.h',
'termptygfx.c', 'termptygfx.h',
'termpty.c', 'termpty.h',
+ 'termptyblock.c', 'termptyblock.h',
'termiointernals.c', 'termiointernals.h',
'termiolink.c', 'termiolink.h',
'config.c', 'config.h',
@@ -234,6 +238,7 @@ if host_os == 'linux'
'backlog_view.c', 'backlog_view.h',
'termsrv.c', 'termsrv.h',
'termpty.c', 'termpty.h',
+ 'termptyblock.c', 'termptyblock.h',
'termptydbl.c', 'termptydbl.h',
'termptyesc.c', 'termptyesc.h',
'termptyops.c', 'termptyops.h',
diff --git a/src/bin/termio.c b/src/bin/termio.c
index db7e850b..d4ade2c7 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -8,6 +8,7 @@
#include "termio.h"
#include "termiolink.h"
#include "termpty.h"
+#include "termptyblock.h"
#include "backlog.h"
#include "extns.h"
#include "termptyops.h"
@@ -4769,7 +4770,7 @@ _smart_pty_command(void *data)
if (strs)
{
char *chid = strs->data;
- blk = termpty_block_chid_get(ty, chid);
+ blk = termpty_block_channel_find(ty, chid);
if (blk)
{
_block_edje_cmds(ty, blk, strs->next, EINA_FALSE);
@@ -4788,8 +4789,9 @@ _smart_pty_command(void *data)
else if (ty->cur_cmd[1] == 'x')
{
const char *chid = &(ty->cur_cmd[2]);
- Termblock *blk = termpty_block_chid_get(ty, chid);
+ Termblock *blk = termpty_block_channel_find(ty, chid);
+ if (!blk) return;
if (blk->edje)
{
blk->no_listen = EINA_TRUE;
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index a6c7dc45..a8fd523d 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -1705,6 +1705,9 @@ termpty_block_free(Termblock *tb)
if (!tb)
return;
+ if (tb->chid && tb->pty && tb->pty->block.chid_map &&
+ (eina_hash_find(tb->pty->block.chid_map, tb->chid) == tb))
+ eina_hash_del(tb->pty->block.chid_map, tb->chid, tb);
eina_stringshare_del(tb->path);
eina_stringshare_del(tb->link);
eina_stringshare_del(tb->chid);
@@ -1783,16 +1786,7 @@ termpty_block_chid_update(Termpty *ty, Termblock *blk)
if (!ty->block.chid_map)
ty->block.chid_map = eina_hash_string_superfast_new(NULL);
if (!ty->block.chid_map) return;
- eina_hash_add(ty->block.chid_map, blk->chid, blk);
-}
-
-Termblock *
-termpty_block_chid_get(const Termpty *ty, const char *chid)
-{
- Termblock *tb;
-
- tb = eina_hash_find(ty->block.chid_map, chid);
- return tb;
+ eina_hash_set(ty->block.chid_map, blk->chid, blk);
}
void
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 31889a65..c9fec755 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -471,7 +471,6 @@ termpty_block_id_get(const Termcell *cell, int *x, int *y)
}
Termblock *termpty_block_get(const Termpty *ty, int id);
void termpty_block_chid_update(Termpty *ty, Termblock *blk);
-Termblock *termpty_block_chid_get(const Termpty *ty, const char *chid);
void termpty_cell_codepoint_att_fill(Termpty *ty, Eina_Unicode codepoint, Termatt att, Termcell *dst, int n);
void termpty_cells_set_content(Termpty *ty, Termcell *cells,
diff --git a/src/bin/termptyblock.c b/src/bin/termptyblock.c
new file mode 100644
index 00000000..dddb5ed7
--- /dev/null
+++ b/src/bin/termptyblock.c
@@ -0,0 +1,72 @@
+#include "private.h"
+#include <Elementary.h>
+#include <Ecore_Input.h>
+#include <Ecore_IMF.h>
+#include <Ecore_IMF_Evas.h>
+#include "termpty.h"
+#include "termptyblock.h"
+
+Termblock *
+termpty_block_channel_find(const Termpty *ty, const char *chid)
+{
+ if (!ty->block.chid_map) return NULL;
+ return eina_hash_find(ty->block.chid_map, chid);
+}
+
+#if defined(BINARY_TYTEST)
+#include <assert.h>
+#include <string.h>
+#include "unit_tests.h"
+
+int
+tytest_termpty_block_channel_find(void)
+{
+ Termpty ty;
+ Termblock *blk;
+
+ memset(&ty, 0, sizeof(ty));
+ assert(termpty_block_channel_find(&ty, "none") == NULL);
+
+ blk = termpty_block_new(&ty, 2, 2, "/tmp/a.png", NULL);
+ assert(blk);
+ blk->chid = eina_stringshare_add("chan");
+ termpty_block_chid_update(&ty, blk);
+ assert(termpty_block_channel_find(&ty, "chan") == blk);
+ assert(termpty_block_channel_find(&ty, "other") == NULL);
+
+ eina_hash_del(ty.block.blocks, &blk->id, blk);
+ assert(termpty_block_channel_find(&ty, "chan") == NULL);
+
+ eina_hash_free(ty.block.blocks);
+ eina_hash_free(ty.block.chid_map);
+ return 0;
+}
+
+int
+tytest_termpty_block_channel_find_newer_claims(void)
+{
+ Termpty ty;
+ Termblock *old_blk, *new_blk;
+
+ memset(&ty, 0, sizeof(ty));
+
+ old_blk = termpty_block_new(&ty, 1, 1, "/tmp/a.png", NULL);
+ assert(old_blk);
+ old_blk->chid = eina_stringshare_add("dup");
+ termpty_block_chid_update(&ty, old_blk);
+
+ new_blk = termpty_block_new(&ty, 1, 1, "/tmp/b.png", NULL);
+ assert(new_blk);
+ new_blk->chid = eina_stringshare_add("dup");
+ termpty_block_chid_update(&ty, new_blk);
+ assert(termpty_block_channel_find(&ty, "dup") == new_blk);
+
+ /* Freeing the old block must not take the newer claim with it. */
+ eina_hash_del(ty.block.blocks, &old_blk->id, old_blk);
+ assert(termpty_block_channel_find(&ty, "dup") == new_blk);
+
+ eina_hash_free(ty.block.blocks);
+ eina_hash_free(ty.block.chid_map);
+ return 0;
+}
+#endif
diff --git a/src/bin/termptyblock.h b/src/bin/termptyblock.h
new file mode 100644
index 00000000..54006c0c
--- /dev/null
+++ b/src/bin/termptyblock.h
@@ -0,0 +1,8 @@
+#ifndef TERMINOLOGY_TERMPTY_BLOCK_H_
+#define TERMINOLOGY_TERMPTY_BLOCK_H_ 1
+
+/* The block that registered the channel chid, or NULL when chid is unknown,
+ * the block was freed, or no block has been registered yet. */
+Termblock *termpty_block_channel_find(const Termpty *ty, const char *chid);
+
+#endif
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 42c574f3..a23ce2e3 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -109,6 +109,8 @@ static struct {
{ "resize_screen2_link_refs", tytest_resize_screen2_link_refs},
{ "backlog_block_refs", tytest_backlog_block_refs},
{ "termpty_free_backlog_block", tytest_termpty_free_backlog_block},
+ { "termpty_block_channel_find", tytest_termpty_block_channel_find},
+ { "termpty_block_channel_find_newer_claims", tytest_termpty_block_channel_find_newer_claims},
{ "backlog_row_get_args", tytest_backlog_row_get_args},
{ "percent_decode", tytest_percent_decode},
{ "sgr_58_no_leak", tytest_sgr_58_no_leak},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 15d038db..1b5a5639 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -6,6 +6,8 @@ typedef int (*tytest_func)(void);
/* list of tests */
int tytest_dummy(void);
+int tytest_termpty_block_channel_find(void);
+int tytest_termpty_block_channel_find_newer_claims(void);
int tytest_write_hook(void);
int tytest_backlog_long_wrap(void);
int tytest_backlog_append_fail(void);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.