From d8d8cb8c4959ee422bfb255b4f776478fd9d1f24 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan.bosch@dovecot.fi>
Date: Fri, 5 Jan 2018 21:44:29 +0100
Subject: [PATCH] sieve-extprograms plugin: execute extension: Fix handling big
 output from external program.

The output buffer was on the data stack, which leads to big trouble when the
buffer needs to grow in a deeper stack level.
---
 src/plugins/sieve-extprograms/cmd-execute.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/plugins/sieve-extprograms/cmd-execute.c b/src/plugins/sieve-extprograms/cmd-execute.c
index 5defe1f02..052998d69 100644
--- a/src/plugins/sieve-extprograms/cmd-execute.c
+++ b/src/plugins/sieve-extprograms/cmd-execute.c
@@ -378,7 +378,7 @@ static int cmd_execute_operation_execute
 			// FIXME: limit output size
 			struct ostream *outdata;
 
-			outbuf = buffer_create_dynamic(pool_datastack_create(), 1024);
+			outbuf = buffer_create_dynamic(default_pool, 1024);
 			outdata = o_stream_create_buffer(outbuf);
 			sieve_extprogram_set_output(sprog, outdata);
 			o_stream_unref(&outdata);
@@ -389,6 +389,8 @@ static int cmd_execute_operation_execute
 
 			if ( sieve_extprogram_set_input_mail(sprog, mail) < 0 ) {
 				sieve_extprogram_destroy(&sprog);
+				if ( outbuf != NULL )
+					buffer_free(&outbuf);
 				return sieve_runtime_mail_error(renv, mail,
 					"execute action: failed to read input message");
 			}
-- 
GitLab