dovecot-2.1: doveadm: Fixed crash with proxying some commands.

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 18 13:19:49 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/9fc78d06252c
changeset: 14563:9fc78d06252c
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 18 13:19:41 2012 +0300
description:
doveadm: Fixed crash with proxying some commands.

diffstat:

 src/doveadm/doveadm-print.c |  17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diffs (51 lines):

diff -r a28c8043842d -r 9fc78d06252c src/doveadm/doveadm-print.c
--- a/src/doveadm/doveadm-print.c	Sat Jun 16 02:03:53 2012 +0300
+++ b/src/doveadm/doveadm-print.c	Mon Jun 18 13:19:41 2012 +0300
@@ -18,6 +18,7 @@
 	const struct doveadm_print_vfuncs *v;
 
 	unsigned int header_idx;
+	bool print_stream_open;
 };
 
 static struct doveadm_print_context *ctx;
@@ -52,7 +53,7 @@
 	doveadm_print_header(key_title, key_title, 0);
 }
 
-void doveadm_print(const char *value)
+static void doveadm_print_sticky_headers(void)
 {
 	const struct doveadm_print_header_context *headers;
 	unsigned int count;
@@ -68,7 +69,13 @@
 			break;
 		}
 	}
+}
 
+void doveadm_print(const char *value)
+{
+	i_assert(!ctx->print_stream_open);
+
+	doveadm_print_sticky_headers();
 	ctx->v->print(value);
 	ctx->header_idx++;
 }
@@ -82,9 +89,15 @@
 
 void doveadm_print_stream(const void *value, size_t size)
 {
+	if (!ctx->print_stream_open) {
+		doveadm_print_sticky_headers();
+		ctx->print_stream_open = TRUE;
+	}
 	ctx->v->print_stream(value, size);
-	if (size == 0)
+	if (size == 0) {
 		ctx->header_idx++;
+		ctx->print_stream_open = FALSE;
+	}
 }
 
 void doveadm_print_sticky(const char *key, const char *value)


More information about the dovecot-cvs mailing list