summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2017-12-20 13:01:43 +0100
committerKarel Zak2017-12-20 13:01:43 +0100
commit43afa84581de8984aa00ef2e9208198929f72ddf (patch)
treeca6b08e1546be3fccbef69d957afcad87b26459a /lib
parentlibfdisk: (gpt) use fdisk_warn() for failed name setting (diff)
downloadkernel-qcow2-util-linux-43afa84581de8984aa00ef2e9208198929f72ddf.tar.gz
kernel-qcow2-util-linux-43afa84581de8984aa00ef2e9208198929f72ddf.tar.xz
kernel-qcow2-util-linux-43afa84581de8984aa00ef2e9208198929f72ddf.zip
lib/mbsalign: encode \x to \xecx
Don't encode stand alone '\', our encoding is about \x<hex>, so we need to care about \x prefix only. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/mbsalign.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/mbsalign.c b/lib/mbsalign.c
index dce1a1321..07fc313b8 100644
--- a/lib/mbsalign.c
+++ b/lib/mbsalign.c
@@ -54,7 +54,8 @@ size_t mbs_safe_nwidth(const char *buf, size_t bufsz, size_t *sz)
last = p + (bufsz - 1);
while (p && *p && p <= last) {
- if (*p == '\\' || iscntrl((unsigned char) *p)) {
+ if ((p < last && *p == '\\' && *(p + 1) == 'x')
+ || iscntrl((unsigned char) *p)) {
width += 4, bytes += 4; /* *p encoded to \x?? */
p++;
}
@@ -135,7 +136,8 @@ char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf, const c
continue;
}
- if (*p == '\\' || iscntrl((unsigned char) *p)) {
+ if ((*p == '\\' && *(p + 1) == 'x')
+ || iscntrl((unsigned char) *p)) {
sprintf(r, "\\x%02x", (unsigned char) *p);
r += 4;
*width += 4;
@@ -239,6 +241,10 @@ char *mbs_invalid_encode_to_buffer(const char *s, size_t *width, char *buf)
(*width)++;
*r++ = *p;
}
+ } else if (*p == '\\' && *(p + 1) == 'x') {
+ sprintf(r, "\\x%02x", (unsigned char) *p);
+ r += 4;
+ *width += 4;
} else {
memcpy(r, p, len);
r += len;