]> git.ipfire.org Git - thirdparty/systemd.git/commit
string-util: Prevent infinite loop pegging CPU on malformed ESC input
authorChris Down <chris@chrisdown.name>
Sat, 14 Feb 2026 16:40:14 +0000 (00:40 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 27 Feb 2026 21:57:05 +0000 (21:57 +0000)
commitf15cfc67632c2a207caed1c5ca18ade6023763e5
tree2a9fab5e5edaa21b3df45308971395a5f2744e65
parente840b9ff311a41df923f41f912165f29b0a61072
string-util: Prevent infinite loop pegging CPU on malformed ESC input

string_has_ansi_sequence() currently does this to look for ESC input:

    t = memchr(s, 0x1B, ...)

So each iteration re-searches from the original start pointer. But if we
find an ESC byte that does *not* start a valid ANSI sequence (like "\x1B
", or an ESC at the end of the string), then ansi_sequence_length()
returns 0, and if that ESC is still in the search window, we will just
spin consuming 100% CPU forever.

Fix this by always advancing past rejected ESC bytes.

(cherry picked from commit 0a664310311b9b2abc79978eb4427c36268c1296)
(cherry picked from commit 21f6f686b4e0253ad74861c349f86d53e84d582b)
(cherry picked from commit 123d536eccaffea66378d87ebeb29c0042931976)
src/basic/string-util.c
src/test/test-ellipsize.c