From: Timo Sirainen Date: Sat, 21 Apr 2018 12:41:44 +0000 (+0300) Subject: doveadm dump: Don't truncate dovecot.index.cache values at NULs X-Git-Tag: 2.3.9~1983 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f456ea32afed46e62b06ef69c1965743fd73057;p=thirdparty%2Fdovecot%2Fcore.git doveadm dump: Don't truncate dovecot.index.cache values at NULs --- diff --git a/src/doveadm/doveadm-dump-index.c b/src/doveadm/doveadm-dump-index.c index 58a1b3e372..9abc535c79 100644 --- a/src/doveadm/doveadm-dump-index.c +++ b/src/doveadm/doveadm-dump-index.c @@ -509,13 +509,23 @@ dump_cache_mime_parts(string_t *str, const void *data, unsigned int size) dump_message_part(str, part); } +static void +dump_cache_append_string(string_t *str, const unsigned char *data, + unsigned int size) +{ + /* cached strings end with NUL */ + if (size > 0 && data[size-1] == '\0') + size--; + str_append_data(str, data, size); +} + static void dump_cache_snippet(string_t *str, const unsigned char *data, unsigned int size) { if (size == 0) return; str_printfa(str, " (version=%u: ", data[0]); - str_append_n(str, data+1, size-1); + dump_cache_append_string(str, data+1, size-1); str_append_c(str, ')'); } @@ -567,8 +577,7 @@ static void dump_cache(struct mail_cache_view *cache_view, unsigned int seq) dump_cache_snippet(str, data, size); break; case MAIL_CACHE_FIELD_STRING: - if (size > 0) - str_printfa(str, "%.*s", (int)size, (const char *)data); + dump_cache_append_string(str, data, size); break; case MAIL_CACHE_FIELD_HEADER: { const uint32_t *lines = data; @@ -608,7 +617,8 @@ static void dump_cache(struct mail_cache_view *cache_view, unsigned int seq) break; } - printf("%s\n", str_c(str)); + fwrite(str_data(str), 1, str_len(str), stdout); + putchar('\n'); } if (ret < 0) printf(" - broken cache\n");