Skip to content

Commit

Permalink
mail-filter: Add missing error handling in ostream-ext-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Feb 24, 2017
1 parent 850778e commit f64f2d4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/plugins/mail-filter/ostream-ext-filter.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit f64f2d4

Please sign in to comment.