From 49b83e5adf05369e437e34785f9c8d7cdced37a9 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 26 Aug 2019 17:51:53 +0100 Subject: [PATCH] mdbx: import - ITS#9068 fix backslash escaping. mdb_load wasn't properly inserting escaped backslashes into the data. mdb_dump wasn't escaping backslashes when generating printable output. Change-Id: I94796846f77f0af1f50214dde0c701566cc5e9ff --- mdb_dump.c | 2 ++ mdb_load.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mdb_dump.c b/mdb_dump.c index 485f8f4f..27ae8b34 100644 --- a/mdb_dump.c +++ b/mdb_dump.c @@ -67,6 +67,8 @@ static void text(MDB_val *v) end = c + v->mv_size; while (c < end) { if (isprint(*c)) { + if (*c == '\\') + putchar('\\'); putchar(*c); } else { putchar('\\'); diff --git a/mdb_load.c b/mdb_load.c index e2cddd53..73a3c19c 100644 --- a/mdb_load.c +++ b/mdb_load.c @@ -241,7 +241,7 @@ badend: while (c2 < end) { if (*c2 == '\\') { if (c2[1] == '\\') { - c1++; c2 += 2; + *c1++ = *c2; } else { if (c2+3 > end || !isxdigit(c2[1]) || !isxdigit(c2[2])) { Eof = 1; @@ -249,8 +249,8 @@ badend: return EOF; } *c1++ = unhex(++c2); - c2 += 2; } + c2 += 2; } else { /* copies are redundant when no escapes were used */ *c1++ = *c2++;