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 4aaf67c433dee8945fa07a5dbac2cd0bfc4b93d7
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 22 20:52:21 2026 -0600

    termio: bound the arguments of edje block messages
    
    The argument count of an edje message comes from program output and
    sized an alloca() unchecked. A huge value faulted, and a negative one
    moved the stack pointer so that the following writes landed in live
    frames: displaying a file could corrupt the stack.
    
    A message now needs as many arguments as it claims, and is otherwise
    dropped along with the rest of the block's commands. A block record
    read from a session is held to what a live escape can produce, which
    also bounds the total stack these messages can use.
---
 src/bin/termio.c       | 15 ++++++++++
 src/bin/termptyblock.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++--
 src/bin/termptyblock.h |  6 ++++
 src/bin/tytest.c       |  1 +
 src/bin/unit_tests.h   |  1 +
 5 files changed, 100 insertions(+), 3 deletions(-)

diff --git a/src/bin/termio.c b/src/bin/termio.c
index 2776df87..81672efe 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -2696,6 +2696,9 @@ _block_edje_cmds(Termpty *ty, Termblock *blk, Eina_List *cmds, Eina_Bool created
                   int i, count;
 
                   GETI(count);
+                  if (!termpty_block_msg_count_valid(count,
+                                                     l->next))
+                    return;
                   m = alloca(sizeof(Edje_Message_String_Set) +
                              ((count - 1) * sizeof(char *)));
                   m->count = count;
@@ -2713,6 +2716,9 @@ _block_edje_cmds(Termpty *ty, Termblock *blk, Eina_List *cmds, Eina_Bool created
                   int i, count;
 
                   GETI(count);
+                  if (!termpty_block_msg_count_valid(count,
+                                                     l->next))
+                    return;
                   m = alloca(sizeof(Edje_Message_Int_Set) +
                              ((count - 1) * sizeof(int)));
                   m->count = count;
@@ -2730,6 +2736,9 @@ _block_edje_cmds(Termpty *ty, Termblock *blk, Eina_List *cmds, Eina_Bool created
                   int i, count;
 
                   GETI(count);
+                  if (!termpty_block_msg_count_valid(count,
+                                                     l->next))
+                    return;
                   m = alloca(sizeof(Edje_Message_Float_Set) +
                              ((count - 1) * sizeof(double)));
                   m->count = count;
@@ -2767,6 +2776,9 @@ _block_edje_cmds(Termpty *ty, Termblock *blk, Eina_List *cmds, Eina_Bool created
                   int i, count;
 
                   GETI(count);
+                  if (!termpty_block_msg_count_valid(count,
+                                                     l->next ? l->next->next : NULL))
+                    return;
                   m = alloca(sizeof(Edje_Message_String_Int_Set) +
                              ((count - 1) * sizeof(int)));
                   GETS(m->str);
@@ -2785,6 +2797,9 @@ _block_edje_cmds(Termpty *ty, Termblock *blk, Eina_List *cmds, Eina_Bool created
                   int i, count;
 
                   GETI(count);
+                  if (!termpty_block_msg_count_valid(count,
+                                                     l->next ? l->next->next : NULL))
+                    return;
                   m = alloca(sizeof(Edje_Message_String_Float_Set) +
                              ((count - 1) * sizeof(double)));
                   GETS(m->str);
diff --git a/src/bin/termptyblock.c b/src/bin/termptyblock.c
index 8be79418..24a8e590 100644
--- a/src/bin/termptyblock.c
+++ b/src/bin/termptyblock.c
@@ -283,7 +283,8 @@ termpty_block_deserialize(Termblock *blk, const void *buf, uint32_t length)
    memcpy(&head, buf, sizeof(head));
    at = (const char *)buf + sizeof(head);
    if (!_block_size_ok(head.w) || !_block_size_ok(head.h) ||
-       (head.flags & ~RECORD_FLAGS_ALL) || (head.ncmds > (size_t)(end - at)))
+       (head.flags & ~RECORD_FLAGS_ALL) || (head.ncmds > (size_t)(end - at)) ||
+       (head.ncmds > TERMPTY_TY_ESCAPE_MAX / 2))
      return EINA_FALSE;
    /* the media code reads the path of any block that is not an edje one */
    if (!(head.flags & (RECORD_PATH | RECORD_EDJE)))
@@ -297,7 +298,7 @@ termpty_block_deserialize(Termblock *blk, const void *buf, uint32_t length)
    for (i = 0; i < head.ncmds; i++)
      {
         cmd = _record_string_get(&at, end);
-        if (!cmd)
+        if ((!cmd) || (!cmd[0]))
           goto bad;
         copy = strdup(cmd);
         if (!copy)
@@ -325,8 +326,19 @@ bad:
    return EINA_FALSE;
 }
 
+Eina_Bool
+termpty_block_msg_count_valid(int count, const Eina_List *args)
+{
+   if (count < 0)
+     return EINA_FALSE;
+   for (; count && args; count--)
+     args = args->next;
+   return count == 0;
+}
+
 #if defined(BINARY_TYTEST)
 #include <assert.h>
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include "unit_tests.h"
@@ -445,7 +457,7 @@ tytest_termpty_block_serialize(void)
 {
    Termblock src = { 0 }, dst = { 0 };
    Block_Record_Head head;
-   char buf[256], bad[256];
+   char buf[256], bad[256], *big;
    uint32_t len, n;
 
    _block_fill(&src, 3, 2, "/tmp/a.edj", "https://l", "chan");
@@ -491,6 +503,41 @@ tytest_termpty_block_serialize(void)
    assert(!termpty_block_deserialize(&dst, bad, len));
    assert(_block_empty(&dst));
 
+   /* a command with nothing in it, or more commands than an escape can
+    * hold, makes a message that could size an alloca past the stack */
+   _block_clear(&src);
+   _block_fill(&src, 1, 1, "/tmp/a.edj", NULL, NULL);
+   src.edje = EINA_TRUE;
+   src.cmds = eina_list_append(src.cmds, strdup(""));
+   len = termpty_block_serialize(&src, buf, sizeof(buf));
+   assert(len > 0 && len < sizeof(buf));
+   assert(!termpty_block_deserialize(&dst, buf, len));
+   assert(_block_empty(&dst));
+   _block_clear(&src);
+   _block_fill(&src, 1, 1, "/tmp/a.edj", NULL, NULL);
+   src.edje = EINA_TRUE;
+   for (n = 0; n <= TERMPTY_TY_ESCAPE_MAX / 2; n++)
+     src.cmds = eina_list_append(src.cmds, strdup("x"));
+   len = termpty_block_serialize(&src, NULL, 0);
+   big = malloc(len);
+   assert(big);
+   assert(termpty_block_serialize(&src, big, len) == len);
+   assert(!termpty_block_deserialize(&dst, big, len));
+   assert(_block_empty(&dst));
+   free(big);
+   _block_clear(&src);
+   _block_fill(&src, 1, 1, "/tmp/a.edj", NULL, NULL);
+   src.edje = EINA_TRUE;
+   for (n = 0; n < TERMPTY_TY_ESCAPE_MAX / 2; n++)
+     src.cmds = eina_list_append(src.cmds, strdup("x"));
+   len = termpty_block_serialize(&src, NULL, 0);
+   big = malloc(len);
+   assert(big);
+   assert(termpty_block_serialize(&src, big, len) == len);
+   assert(termpty_block_deserialize(&dst, big, len));
+   free(big);
+   _block_clear(&dst);
+
    /* no link, chid or commands is not an empty one */
    _block_clear(&src);
    _block_fill(&src, 1, 1, "/tmp/b.png", NULL, NULL);
@@ -599,4 +646,31 @@ tytest_termpty_block_channel_find_newer_claims(void)
    eina_hash_free(ty.block.chid_map);
    return 0;
 }
+
+int
+tytest_termpty_block_msg_count(void)
+{
+   Eina_List *args = NULL;
+
+   assert(termpty_block_msg_count_valid(0, NULL));
+   assert(!termpty_block_msg_count_valid(1, NULL));
+   assert(!termpty_block_msg_count_valid(-1, NULL));
+
+   args = eina_list_append(args, "1");
+   args = eina_list_append(args, "2");
+   args = eina_list_append(args, "3");
+   assert(termpty_block_msg_count_valid(0, args));
+   assert(termpty_block_msg_count_valid(2, args));
+   assert(termpty_block_msg_count_valid(3, args));
+   assert(!termpty_block_msg_count_valid(4, args));
+   assert(!termpty_block_msg_count_valid(1000000000, args));
+   assert(!termpty_block_msg_count_valid(INT_MAX, args));
+   assert(!termpty_block_msg_count_valid(-1, args));
+   assert(!termpty_block_msg_count_valid(INT_MIN, args));
+   assert(termpty_block_msg_count_valid(2, eina_list_nth_list(args, 1)));
+   assert(!termpty_block_msg_count_valid(3, eina_list_nth_list(args, 1)));
+   assert(termpty_block_msg_count_valid(0, eina_list_nth_list(args, 2)->next));
+   eina_list_free(args);
+   return 0;
+}
 #endif
diff --git a/src/bin/termptyblock.h b/src/bin/termptyblock.h
index ab4a13f0..e13ebbf4 100644
--- a/src/bin/termptyblock.h
+++ b/src/bin/termptyblock.h
@@ -23,4 +23,10 @@ uint32_t termpty_block_serialize(const Termblock *blk, void *buf,
 Eina_Bool termpty_block_deserialize(Termblock *blk, const void *buf,
                                     uint32_t length);
 
+/* Whether count, read from a message command of an edje block, can size a
+ * message holding count values taken from args, the items that follow the
+ * count. The count comes from program output: it must not be negative nor
+ * exceed what args holds. */
+Eina_Bool termpty_block_msg_count_valid(int count, const Eina_List *args);
+
 #endif
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index c61b8c3b..9ccd53b6 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -112,6 +112,7 @@ static struct {
        { "termpty_block_command", tytest_termpty_block_command},
        { "termpty_block_serialize", tytest_termpty_block_serialize},
        { "termpty_block_channel_find", tytest_termpty_block_channel_find},
+       { "termpty_block_msg_count", tytest_termpty_block_msg_count},
        { "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},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index ffd49536..57d2d2d4 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -9,6 +9,7 @@ int tytest_dummy(void);
 int tytest_termpty_block_command(void);
 int tytest_termpty_block_serialize(void);
 int tytest_termpty_block_channel_find(void);
+int tytest_termpty_block_msg_count(void);
 int tytest_termpty_block_channel_find_newer_claims(void);
 int tytest_write_hook(void);
 int tytest_backlog_long_wrap(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to