dovecot-2.2: iostream-rawlog: Avoid crashing more if write() to ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 29 21:31:28 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/ce342fd3cae7
changeset: 15351:ce342fd3cae7
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 29 21:28:45 2012 +0200
description:
iostream-rawlog: Avoid crashing more if write() to rawlog fails.

diffstat:

 src/lib/iostream-rawlog.c |  38 ++++++++++++++++++++++++--------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diffs (88 lines):

diff -r bb095315d025 -r ce342fd3cae7 src/lib/iostream-rawlog.c
--- a/src/lib/iostream-rawlog.c	Mon Oct 29 20:48:08 2012 +0200
+++ b/src/lib/iostream-rawlog.c	Mon Oct 29 21:28:45 2012 +0200
@@ -20,20 +20,22 @@
 
 #define RAWLOG_MAX_LINE_LEN 8192
 
-static void
+static int
 rawlog_write(struct rawlog_iostream *rstream, const void *data, size_t size)
 {
 	if (rstream->rawlog_fd == -1)
-		return;
+		return -1;
 
 	if (write_full(rstream->rawlog_fd, data, size) < 0) {
 		i_error("rawlog_istream.write(%s) failed: %m",
 			rstream->rawlog_path);
 		iostream_rawlog_close(rstream);
+		return -1;
 	}
+	return 0;
 }
 
-static void
+static int
 rawlog_write_timestamp(struct rawlog_iostream *rstream, bool line_ends)
 {
 	unsigned char data[MAX_INT_STRLEN + 6 + 1 + 3];
@@ -48,7 +50,7 @@
 		str_append_c(&buf, line_ends ? ':' : '>');
 		str_append_c(&buf, ' ');
 	}
-	rawlog_write(rstream, buf.data, buf.used);
+	return rawlog_write(rstream, buf.data, buf.used);
 }
 
 void iostream_rawlog_init(struct rawlog_iostream *rstream,
@@ -66,18 +68,23 @@
 {
 	size_t i, start;
 
-	if (!rstream->line_continued)
-		rawlog_write_timestamp(rstream, TRUE);
+	if (!rstream->line_continued) {
+		if (rawlog_write_timestamp(rstream, TRUE) < 0)
+			return;
+	}
 
 	for (start = 0, i = 1; i < size; i++) {
 		if (data[i-1] == '\n') {
-			rawlog_write(rstream, data + start, i - start);
-			rawlog_write_timestamp(rstream, TRUE);
+			if (rawlog_write(rstream, data + start, i - start) < 0 ||
+			    rawlog_write_timestamp(rstream, TRUE) < 0)
+				return;
 			start = i;
 		}
 	}
-	if (start != size)
-		rawlog_write(rstream, data + start, size - start);
+	if (start != size) {
+		if (rawlog_write(rstream, data + start, size - start) < 0)
+			return;
+	}
 	rstream->line_continued = data[size-1] != '\n';
 }
 
@@ -109,12 +116,15 @@
 			pos = size;
 		}
 
-		rawlog_write_timestamp(rstream, line_ends);
+		if (rawlog_write_timestamp(rstream, line_ends) < 0)
+			break;
 		if (rstream->buffer->used > 0) {
-			rawlog_write(rstream, rstream->buffer->data,
-				     rstream->buffer->used);
+			if (rawlog_write(rstream, rstream->buffer->data,
+					 rstream->buffer->used) < 0)
+				break;
 		}
-		rawlog_write(rstream, data, pos);
+		if (rawlog_write(rstream, data, pos) < 0)
+			break;
 
 		data += pos;
 		size -= pos;


More information about the dovecot-cvs mailing list