diff options
Diffstat (limited to 'source3/lib/ldb_compat.c')
-rw-r--r-- | source3/lib/ldb_compat.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source3/lib/ldb_compat.c b/source3/lib/ldb_compat.c index 36a29e6833..494d381ad1 100644 --- a/source3/lib/ldb_compat.c +++ b/source3/lib/ldb_compat.c @@ -84,8 +84,13 @@ static struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str) return ret; } - - +static bool need_encode(unsigned char cval) +{ + if (cval < 0x20 || cval > 0x7E || strchr(" *()\\&|!\"", cval)) { + return true; + } + return false; +} /* encode a blob as a RFC2254 binary string, escaping any @@ -99,7 +104,7 @@ char *ldb_binary_encode(void *mem_ctx, struct ldb_val val) unsigned char *buf = val.data; for (i=0;i<val.length;i++) { - if (!isprint(buf[i]) || strchr(" *()\\&|!\"", buf[i])) { + if (need_encode(buf[i])) { len += 2; } } @@ -108,7 +113,7 @@ char *ldb_binary_encode(void *mem_ctx, struct ldb_val val) len = 0; for (i=0;i<val.length;i++) { - if (!isprint(buf[i]) || strchr(" *()\\&|!\"", buf[i])) { + if (need_encode(buf[i])) { snprintf(ret+len, 4, "\\%02X", buf[i]); len += 3; } else { |