dovecot-2.2: istream-seekable: Don't crash when seeking forwards...

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 23 17:21:57 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/2784b88a4260
changeset: 16313:2784b88a4260
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 23 17:21:46 2013 +0300
description:
istream-seekable: Don't crash when seeking forwards past the data we haven't read yet.

diffstat:

 src/lib/istream-seekable.c |  15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diffs (32 lines):

diff -r 43e7606b31e2 -r 2784b88a4260 src/lib/istream-seekable.c
--- a/src/lib/istream-seekable.c	Tue Apr 23 16:20:48 2013 +0300
+++ b/src/lib/istream-seekable.c	Tue Apr 23 17:21:46 2013 +0300
@@ -345,6 +345,20 @@
 	return 0;
 }
 
+static void i_stream_seekable_seek(struct istream_private *stream,
+				   uoff_t v_offset, bool mark)
+{
+	if (v_offset <= stream->istream.v_offset) {
+		/* seeking backwards */
+		stream->istream.v_offset = v_offset;
+		stream->skip = stream->pos = 0;
+	} else {
+		/* we can't skip over data we haven't yet read and written to
+		   our buffer/temp file */
+		i_stream_default_seek_nonseekable(stream, v_offset, mark);
+	}
+}
+
 struct istream *
 i_streams_merge(struct istream *input[], size_t max_buffer_size,
 		int (*fd_callback)(const char **path_r, void *context),
@@ -388,6 +402,7 @@
 
 	sstream->istream.read = i_stream_seekable_read;
 	sstream->istream.stat = i_stream_seekable_stat;
+	sstream->istream.seek = i_stream_seekable_seek;
 
 	sstream->istream.istream.readable_fd = FALSE;
 	sstream->istream.istream.blocking = blocking;


More information about the dovecot-cvs mailing list