]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail-filter: Add missing error handling in ostream-ext-filter
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 24 Feb 2017 10:27:02 +0000 (12:27 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 24 Feb 2017 10:27:02 +0000 (12:27 +0200)
src/plugins/mail-filter/ostream-ext-filter.c

index eff0a5359e5bd85022ef78eaf1f2d7ec9cb00a6c..dfee69d07014d51f26a44142b0260a9e34fbf3e5 100644 (file)
@@ -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;
 }