]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mbsalign: encode backslash to prevent ambiguity
authorVaclav Dolezal <vdolezal@redhat.com>
Fri, 8 Sep 2017 14:36:26 +0000 (16:36 +0200)
committerVaclav Dolezal <vdolezal@redhat.com>
Wed, 29 Nov 2017 15:21:07 +0000 (16:21 +0100)
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
lib/mbsalign.c

index 78ab12a0da91dec44ea8e0487661f2451ff78849..dce1a1321479e02747e99f204b61866bc0f345af 100644 (file)
@@ -54,7 +54,7 @@ size_t mbs_safe_nwidth(const char *buf, size_t bufsz, size_t *sz)
                last = p + (bufsz - 1);
 
        while (p && *p && p <= last) {
-               if (iscntrl((unsigned char) *p)) {
+               if (*p == '\\' || iscntrl((unsigned char) *p)) {
                        width += 4, bytes += 4;         /* *p encoded to \x?? */
                        p++;
                }
@@ -135,7 +135,7 @@ char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf, const c
                        continue;
                }
 
-               if (iscntrl((unsigned char) *p)) {
+               if (*p == '\\' || iscntrl((unsigned char) *p)) {
                        sprintf(r, "\\x%02x", (unsigned char) *p);
                        r += 4;
                        *width += 4;