changeset 15640:20a545f932e3

i_stream_read_next_line() now sets stream_errno=ENOBUFS if input buffer gets full. Previously the caller couldn't easily separate this condition from "more data needed", potentially causing infinite loops.
author Timo Sirainen <tss@iki.fi>
date Mon, 14 Jan 2013 07:57:39 +0200
parents 6654ed22af78
children 19403b3926f9
files src/lib/istream.c src/lib/istream.h
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/istream.c	Sun Jan 13 19:15:37 2013 +0200
+++ b/src/lib/istream.c	Mon Jan 14 07:57:39 2013 +0200
@@ -387,8 +387,15 @@
 		if (line != NULL)
 			break;
 
-		if (i_stream_read(stream) <= 0)
+		switch (i_stream_read(stream)) {
+		case -2:
+			stream->stream_errno = ENOBUFS;
+			return NULL;
+		case -1:
 			return i_stream_last_line(stream->real_stream);
+		case 0:
+			return NULL;
+		}
 	}
 	return line;
 }
--- a/src/lib/istream.h	Sun Jan 13 19:15:37 2013 +0200
+++ b/src/lib/istream.h	Mon Jan 14 07:57:39 2013 +0200
@@ -123,7 +123,8 @@
    if the last line should be returned if it doesn't end with LF. */
 char *i_stream_next_line(struct istream *stream);
 /* Like i_stream_next_line(), but reads for more data if needed. Returns NULL
-   if more data is needed or error occurred. */
+   if more data is needed or error occurred. If the input buffer gets full,
+   stream_errno is set to ENOBUFS. */
 char *i_stream_read_next_line(struct istream *stream);
 /* Returns TRUE if the last line read with i_stream_next_line() ended with
    CRLF (instead of LF). */