This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit df742ccaaa49211ec066c09e2ea23947f6c6d96f
Author: Boris Faure <[email protected]>
AuthorDate: Wed Nov 4 16:28:28 2026 +0000

    termptyesc: clamp huge CUP/HVP against the margins
    
    Escape parameters at int's ceiling got through the argument parser:
    the too-large check passed sum == INT32_MAX/10 through, and
    sum * 10 + digit wrapped to a negative int. CUP/HVP then subtracts one
    and, in origin mode (ESC[?6h) with the left margin set by DECSLRM under
    DECLRMM (ESC[?69h ESC[15;30s), adds the left/top margin, which
    overflowed int again; both remaining clamps are upper bounds, so the
    cursor went to a negative column and the next character write went
    through a wild cells pointer.
    
    Reject exactly the overflowing values in the parser, as it already
    rejected everything above them, and clamp the cursor to the screen
    before the margin add, so no legal argument can overflow it. xterm
    keeps the cursor inside the margins for such sequences.
    
    tests/crash_cup_col_over_margin.sh covers the wrap value, the largest
    legal value with and without origin mode, missing parameters, and
    positions given as rows as much as columns.
---
 src/bin/termptyesc.c               | 14 +++++++++++++-
 tests/crash_cup_col_over_margin.sh | 25 +++++++++++++++++++++++++
 tests/tests.results                |  1 +
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 64a3168a..0a454f3d 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -200,7 +200,11 @@ _csi_arg_get_subparam(Termpty *ty, Eina_Unicode **ptr, Eina_Bool *sub_follows)
 
    while ((*b >= '0') && (*b <= '9'))
      {
-        if (sum > INT32_MAX/10 )
+        /* The digit-by-digit add overflows int exactly at
+         * INT32_MAX/10,9 / INT32_MAX, so the boundary has to be
+         * checked before the add, not just past it. */
+        if ((sum > INT32_MAX / 10) ||
+            ((sum == INT32_MAX / 10) && (*b - '0' > INT32_MAX % 10)))
           {
              ERR("Invalid sequence: argument is too large");
              ty->decoding_error = EINA_TRUE;
@@ -2495,6 +2499,12 @@ _handle_esc_csi_cursor_pos_set(Termpty *ty, Eina_Unicode **b,
    cx--;
    if (cx < 0)
      cx = 0;
+   /* Clamp before the origin-mode margins come in: with margins set and an
+    * argument at int's ceiling, cx + left_margin would overflow and sneak
+    * past every clamp below as a negative value, and the next write would
+    * go through a wild cells pointer. */
+   if (cx >= ty->w)
+     cx = ty->w - 1;
    if (ty->termstate.restrict_cursor)
      {
         cx += ty->termstate.left_margin;
@@ -2509,6 +2519,8 @@ _handle_esc_csi_cursor_pos_set(Termpty *ty, Eina_Unicode **b,
    cy--;
    if (cy < 0)
      cy = 0;
+   if (cy >= ty->h)
+     cy = ty->h - 1;
    if (ty->termstate.restrict_cursor)
      {
         cy += ty->termstate.top_margin;
diff --git a/tests/crash_cup_col_over_margin.sh b/tests/crash_cup_col_over_margin.sh
new file mode 100644
index 00000000..9560179a
--- /dev/null
+++ b/tests/crash_cup_col_over_margin.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# CUP/HVP with a column or row at int's ceiling, after DECSLRM gave the
+# cursor arithmetic a nonzero left/top margin to add: the margin add
+# overflowed into a negative cursor, which slipped past the upper-bound
+# clamps and the next write went through a wild cells pointer.
+#
+# Edge cases: the exact overflow value (2147483648 wraps to negative when
+# parsed), the largest legal value (2147483647 has to clamp into the
+# margins, not overflow), same without origin mode, and missing
+# parameters.
+printf '\033[?69h\033[15;30s\033[?6h\033[5;2147483648H'
+printf 'X'
+printf '\033[0;16H'
+printf 'Y'
+printf '\033[5;2147483647H'
+printf 'Z'
+printf '\033[2147483648;2147483647H'
+printf 'W'
+printf '\033[?6l\033[5;2147483648H'
+printf 'V'
+printf '\033[;2147483648H'
+printf 'U'
+printf '\033[2147483648H'
+printf 'T'
+printf 'UVT'
diff --git a/tests/tests.results b/tests/tests.results
index b02b4d00..c0f2c3d7 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -202,3 +202,4 @@ dsr-color-scheme.sh 68f86326864cc9988c84dc20babe4156
 decset-2031.sh 60c4f2ca88a2a4dbae8f7453c633d074
 ascii_run_prefix.sh 5413bed756d01dc51d09609c8512b8ec
 xtgettcap.sh 300a0521bca0f2bf50bc00161f8fc195
+crash_cup_col_over_margin.sh 400a5215c6e74782cbab076e2a81fff7

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

Reply via email to