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

dovecot at dovecot.org dovecot at dovecot.org
Thu May 9 12:31:58 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.1/rev/48199b8e99cc
changeset: 14962:48199b8e99cc
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 09 12:30:53 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 |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (46 lines):

diff -r 23f7cabad194 -r 48199b8e99cc src/lib/istream-seekable.c
--- a/src/lib/istream-seekable.c	Mon May 06 14:33:05 2013 +0300
+++ b/src/lib/istream-seekable.c	Thu May 09 12:30:53 2013 +0300
@@ -290,13 +290,6 @@
 	return ret;
 }
 
-static void i_stream_seekable_seek(struct istream_private *stream,
-				   uoff_t v_offset, bool mark ATTR_UNUSED)
-{
-	stream->istream.v_offset = v_offset;
-	stream->skip = stream->pos = 0;
-}
-
 static const struct stat *
 i_stream_seekable_stat(struct istream_private *stream, bool exact)
 {
@@ -341,6 +334,20 @@
 	}
 }
 
+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(stream, v_offset, mark);
+	}
+}
+
 struct istream *
 i_stream_create_seekable(struct istream *input[],
 			 size_t max_buffer_size,
@@ -394,6 +401,7 @@
 	sstream->istream.read = i_stream_seekable_read;
 	sstream->istream.seek = i_stream_seekable_seek;
 	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