Skip to content

Fix 3 out of bound reads - #65

Merged
kdj0c merged 3 commits into
kmscon:mainfrom
kdj0c:fixes
Aug 14, 2026
Merged

Fix 3 out of bound reads#65
kdj0c merged 3 commits into
kmscon:mainfrom
kdj0c:fixes

Conversation

@kdj0c

@kdj0c kdj0c commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

No description provided.

1) Heap out-of-bounds READ — tsm_screen_tab_left (src/tsm/tsm-screen.c)

A cursor-forward-tab (CHT, ESC [ n I) followed by a wide glyph at the last column
can leave cursor_x > size_x; a following cursor-backward-tab (CBT, ESC [ Z) then
reads tab_ruler[cursor_x - 1], past the size_x-element ruler:

    ==ERROR: AddressSanitizer: heap-buffer-overflow  READ of size 1
        in tsm_screen_tab_left  src/tsm/tsm-screen.c:1354
        in do_csi / do_action / do_trans / tsm_vte_input

Reported-by: Benjamin Ali (glitchfox) <glitchfox@benjaminali.com>
Signed-off-by: Benjamin Ali (glitchfox) <glitchfox@benjaminali.com>
Out-of-bounds READ via unbounded OSC 4 color index — lookup_color (src/tsm/tsm-vte.c)

do_osc_4 (ESC ] 4 ; <index> ; ? ) parses <index> as an unbounded unsigned int and
passes it to lookup_color(int color). A large value wraps to a negative int,
passes the `color < 16` test, and reaches palette_rgb() -> vte->palette[color] —
a wild read that SIGSEGVs:

    ==ERROR: AddressSanitizer: SEGV ... READ memory access
        in palette_rgb   src/tsm/tsm-vte.c:1284
        in lookup_color  src/tsm/tsm-vte.c:1310
        in do_osc_4      src/tsm/tsm-vte.c:2237

The read colour is also written back in the OSC-4 query reply, so a non-faulting
read is an information leak. Large positive indices additionally mis-index
cube_rgb's bval[] and overflow greyscale_rgb — same root cause.

Reported-by: Benjamin Ali (glitchfox) <glitchfox@benjaminali.com>
Signed-off-by: Benjamin Ali (glitchfox) <glitchfox@benjaminali.com>
Out-of-bounds READ of csi_argv[16] — csi_attribute (src/tsm/tsm-vte.c)
csi_argv is int[CSI_ARG_MAX] with CSI_ARG_MAX == 16. In the SGR 38/48 handling,
csi_argv[i + 1] is read before i + 1 is bounds-checked (the i+2 >= csi_argc guard
comes after). An SGR whose 38/48 is the 16th argument reads csi_argv[16]:

    src/tsm/tsm-vte.c:1482: runtime error: index 16 out of bounds for type 'int[16]'
        in csi_attribute -> do_csi -> ... -> tsm_vte_input

Reported-by: Benjamin Ali (glitchfox) <glitchfox@benjaminali.com>
Signed-off-by: Benjamin Ali (glitchfox) <glitchfox@benjaminali.com>
@kdj0c
kdj0c merged commit a9d8da1 into kmscon:main Aug 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants