changeset 21700:28e2d0186a42

mail-filter: Add missing error handling in ostream-ext-filter
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 24 Feb 2017 12:27:02 +0200
parents fbe64fac58c6
children 2e9671812460
files src/plugins/mail-filter/ostream-ext-filter.c
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/mail-filter/ostream-ext-filter.c	Fri Feb 24 12:17:21 2017 +0200
+++ b/src/plugins/mail-filter/ostream-ext-filter.c	Fri Feb 24 12:27:02 2017 +0200
@@ -56,6 +56,8 @@
 	/* send the data to the filter */
 	ret = o_stream_sendv(mstream->ext_out, iov, iov_count);
 	if (ret < 0) {
+		io_stream_set_error(&stream->iostream, "%s",
+				    o_stream_get_error(mstream->ext_out));
 		stream->ostream.stream_errno =
 			mstream->ext_out->stream_errno;
 		return -1;
@@ -98,10 +100,13 @@
 		/* EOF without any input -> assume the script is repoting
 		   failure. pretty ugly way, but currently there's no error
 		   reporting channel. */
+		io_stream_set_error(&stream->iostream, "EOF without input");
 		stream->ostream.stream_errno = EIO;
 		return -1;
 	}
 	if (mstream->ext_in->stream_errno != 0) {
+		io_stream_set_error(&stream->iostream, "%s",
+				    i_stream_get_error(mstream->ext_in));
 		stream->ostream.stream_errno = mstream->ext_in->stream_errno;
 		return -1;
 	}
@@ -125,12 +130,12 @@
 
 	if ((fd = net_connect_unix_with_retries(socket_path, 1000)) < 0) {
 		if (errno == EACCES) {
-			i_error("ext-filter: %s",
+			io_stream_set_error(&mstream->ostream.iostream, "%s",
 				eacces_error_get("net_connect_unix",
 						 socket_path));
 		} else {
-			i_error("ext-filter: net_connect_unix(%s) failed: %m",
-				socket_path);
+			io_stream_set_error(&mstream->ostream.iostream,
+				"net_connect_unix(%s) failed: %m", socket_path);
 		}
 		return -1;
 	}
@@ -148,7 +153,18 @@
 	}
 	str_append_c(str, '\n');
 
-	o_stream_send(mstream->ext_out, str_data(str), str_len(str));
+	ssize_t ret = o_stream_send(mstream->ext_out, str_data(str), str_len(str));
+	if (ret < 0) {
+		io_stream_set_error(&mstream->ostream.iostream, "%s",
+				    o_stream_get_error(mstream->ext_out));
+		mstream->ostream.ostream.stream_errno =
+			mstream->ext_out->stream_errno;
+	} else if ((size_t)ret != str_len(str)) {
+		io_stream_set_error(&mstream->ostream.iostream,
+			"write(%s): Wrote only %"PRIuSIZE_T" of %"PRIuSIZE_T" bytes",
+			socket_path, (size_t)ret, str_len(str));
+		mstream->ostream.ostream.stream_errno = ENOBUFS;
+	}
 	return 0;
 }