]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mbsalign: validate ESC character before processing escape sequences
authorWanBingjiang <wanbingjiang@webray.com.cn>
Tue, 17 Mar 2026 02:19:08 +0000 (10:19 +0800)
committerWanBingjiang <wanbingjiang@webray.com.cn>
Tue, 17 Mar 2026 02:33:10 +0000 (10:33 +0800)
Only process escape sequences when the control character is ESC.
This prevents \n[ or \n( from being misidentified as escape sequences.

Signed-off-by: WanBingjiang <wanbingjiang@webray.com.cn>
lib/mbsalign.c

index 97627537f80cd969158d933c70f7a73a059bad6a..3e79ad10b4e8e8476a607cb44b1317bd541c539a 100644 (file)
@@ -43,8 +43,13 @@ size_t mbs_nwidth(const char *buf, size_t bufsz)
 
        while (p && *p && p <= last) {
                if (iscntrl((unsigned char) *p)) {
+                       char ctrl_char = *p;
                        p++;
 
+                       /* only process escape sequences if the control char is ESC */
+                       if (ctrl_char != '\e')
+                               continue;
+
                        /* try detect "\e[x;ym" and skip on success */
                        if (*p && *p == '[') {
                                const char *e = p;