dovecot-2.2: i_stream_create_seekable_path() created memory corr...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 20 16:14:00 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/e3f8be1bd93a
changeset: 14940:e3f8be1bd93a
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 20 16:13:49 2012 +0300
description:
i_stream_create_seekable_path() created memory corruption

diffstat:

 src/lib/istream-seekable.c |  24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diffs (51 lines):

diff -r 2fc74b72817b -r e3f8be1bd93a src/lib/istream-seekable.c
--- a/src/lib/istream-seekable.c	Mon Aug 20 11:09:42 2012 +0300
+++ b/src/lib/istream-seekable.c	Mon Aug 20 16:13:49 2012 +0300
@@ -392,20 +392,25 @@
 	return i_stream_create(&sstream->istream, NULL, -1);
 }
 
+static bool inputs_are_seekable(struct istream *input[])
+{
+	unsigned int count;
+
+	for (count = 0; input[count] != NULL; count++) {
+		if (!input[count]->seekable)
+			return FALSE;
+	}
+	return TRUE;
+}
+
 struct istream *
 i_stream_create_seekable(struct istream *input[],
 			 size_t max_buffer_size,
 			 int (*fd_callback)(const char **path_r, void *context),
 			 void *context)
 {
-	unsigned int count;
-
 	/* If all input streams are seekable, use concat istream instead */
-	for (count = 0; input[count] != NULL; count++) {
-		if (!input[count]->seekable)
-			break;
-	}
-	if (input[count] == NULL)
+	if (inputs_are_seekable(input))
 		return i_stream_create_concat(input);
 
 	return i_streams_merge(input, max_buffer_size, fd_callback, context);
@@ -445,10 +450,13 @@
 	struct seekable_istream *sstream;
 	struct istream *stream;
 
+	if (inputs_are_seekable(input))
+		return i_stream_create_concat(input);
+
 	stream = i_stream_create_seekable(input, max_buffer_size,
 					  seekable_fd_callback,
 					  i_strdup(temp_path_prefix));
-	sstream = (struct seekable_istream *)stream;
+	sstream = (struct seekable_istream *)stream->real_stream;
 	sstream->free_context = TRUE;
 	return stream;
 }


More information about the dovecot-cvs mailing list