From: Timo Sirainen Date: Fri, 24 Feb 2017 10:27:02 +0000 (+0200) Subject: mail-filter: Add missing error handling in ostream-ext-filter X-Git-Tag: 2.3.0.rc1~1995 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f64f2d4b76128edcd05331fe23e2fac86e9bd9a3;p=thirdparty%2Fdovecot%2Fcore.git mail-filter: Add missing error handling in ostream-ext-filter --- diff --git a/src/plugins/mail-filter/ostream-ext-filter.c b/src/plugins/mail-filter/ostream-ext-filter.c index eff0a5359e..dfee69d070 100644 --- a/src/plugins/mail-filter/ostream-ext-filter.c +++ b/src/plugins/mail-filter/ostream-ext-filter.c @@ -56,6 +56,8 @@ o_stream_mail_filter_sendv(struct ostream_private *stream, /* 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 @@ static int o_stream_mail_filter_flush(struct ostream_private *stream) /* 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 @@ static int filter_connect(struct mail_filter_ostream *mstream, 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 @@ static int filter_connect(struct mail_filter_ostream *mstream, } 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; }