dovecot: Lone CR handling fixes.
dovecot at dovecot.org
dovecot at dovecot.org
Thu Nov 8 02:27:02 EET 2007
details: http://hg.dovecot.org/dovecot/rev/f0f6cec0ac46
changeset: 6725:f0f6cec0ac46
user: Timo Sirainen <tss at iki.fi>
date: Thu Nov 08 02:26:58 2007 +0200
description:
Lone CR handling fixes.
diffstat:
2 files changed, 27 insertions(+), 7 deletions(-)
src/lib/istream-crlf.c | 16 +++++++++++++---
src/tests/test-istream.c | 18 ++++++++++++++----
diffs (90 lines):
diff -r 76fc7245e74b -r f0f6cec0ac46 src/lib/istream-crlf.c
--- a/src/lib/istream-crlf.c Thu Nov 08 01:59:05 2007 +0200
+++ b/src/lib/istream-crlf.c Thu Nov 08 02:26:58 2007 +0200
@@ -99,6 +99,7 @@ static ssize_t i_stream_crlf_read_lf(str
const unsigned char *data;
size_t i, dest, size;
ssize_t ret;
+ int diff;
ret = i_stream_crlf_read_common(cstream);
if (ret <= 0)
@@ -124,13 +125,22 @@ static ssize_t i_stream_crlf_read_lf(str
stream->w_buffer[dest++] = data[0];
}
+ diff = -1;
for (i = 1; i < size && dest < stream->buffer_size; i++) {
- if (data[i] == '\r' && data[i-1] != '\r')
- continue;
+ if (data[i] == '\r') {
+ if (data[i-1] != '\r')
+ continue;
+ } else if (data[i-1] == '\r' && data[i] != '\n') {
+ stream->w_buffer[dest++] = '\r';
+ if (dest == stream->buffer_size) {
+ diff = 0;
+ break;
+ }
+ }
stream->w_buffer[dest++] = data[i];
}
- cstream->pending_cr = data[i-1] == '\r';
+ cstream->pending_cr = data[i+diff] == '\r';
i_stream_skip(cstream->input, i);
ret = dest - stream->pos;
diff -r 76fc7245e74b -r f0f6cec0ac46 src/tests/test-istream.c
--- a/src/tests/test-istream.c Thu Nov 08 01:59:05 2007 +0200
+++ b/src/tests/test-istream.c Thu Nov 08 02:26:58 2007 +0200
@@ -17,11 +17,11 @@ static void test_istream_crlf_input(cons
output = t_str_new(256);
- for (j = 0; j < 2; j++) {
+ for (j = 0; j < 4; j++) {
istream = i_stream_create_from_data(input, input_len);
success = TRUE;
str_truncate(output, 0);
- if (j == 0) {
+ if (j%2 == 0) {
/* drop CRs */
crlf_istream = i_stream_create_lf(istream);
for (i = 0; i < input_len; i++) {
@@ -44,6 +44,16 @@ static void test_istream_crlf_input(cons
pos = 0;
for (i = 1; i <= input_len; i++) {
+ if (j >= 2) {
+ i_stream_unref(&istream);
+ i_stream_unref(&crlf_istream);
+ istream = i_stream_create_from_data(input,
+ input_len);
+ crlf_istream = j%2 == 0 ?
+ i_stream_create_lf(istream) :
+ i_stream_create_crlf(istream);
+ pos = 0;
+ }
istream->real_stream->pos = i;
if (crlf_istream->real_stream->buffer_size != 0) {
/* this is pretty evil */
@@ -69,7 +79,7 @@ static void test_istream_crlf_input(cons
i_stream_unref(&crlf_istream);
i_stream_unref(&istream);
- test_out(t_strdup_printf("test_istream_crlf(%d)", num*2+j),
+ test_out(t_strdup_printf("test_istream_crlf(%d)", num*4+j),
success);
}
}
@@ -77,8 +87,8 @@ static void test_istream_crlf(void)
static void test_istream_crlf(void)
{
const char *input[] = {
+ "\rfoo",
"foo\nbar\r\nbaz\r\r\n",
- "\rfoo",
"\r\nfoo",
"\r\r\n",
"\nfoo"
More information about the dovecot-cvs
mailing list