]> git.ipfire.org Git - thirdparty/util-linux.git/commit
col: fix cur_col underflow on backspace over a wide char
authorAizal Khan <aizumusheer2@gmail.com>
Wed, 1 Jul 2026 13:21:41 +0000 (18:51 +0530)
committerAizal Khan <aizumusheer2@gmail.com>
Wed, 1 Jul 2026 13:21:41 +0000 (18:51 +0530)
commit65627ec56bfeed5fa6fd3edff8e65f3e587fee7e
treed8909bf9f88d3117e42f0ddc248c34031fcace40
parentf9baae05e3b467da0c4e72254dd7018151639a8f
col: fix cur_col underflow on backspace over a wide char

The BS handler in handle_not_graphic() subtracts the last stored
character's width from lns->cur_col (a size_t) and only guards against
cur_col == 0. When the last graphic character is double-width and the
column was reset by CR then advanced by a single space, cur_col is 1 and
cur_col -= 2 wraps to SIZE_MAX. That feeds l_max_col and the stored
c_column, so flush_line() sizes count[] as l_max_col + 1 (== 0) and then
memsets sizeof(size_t) * l_max_col bytes and indexes count[SIZE_MAX] --
an out-of-bounds write reachable from stdin under a UTF-8 locale. Clamp
the subtraction so the column cannot go below zero.

Signed-off-by: Aizal Khan <aizumusheer2@gmail.com>
text-utils/col.c