Diffstat (limited to 'libetpan/src/data-types/mailstream_helper.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libetpan/src/data-types/mailstream_helper.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libetpan/src/data-types/mailstream_helper.c b/libetpan/src/data-types/mailstream_helper.c index 2f0b9ae..f0ddf51 100644 --- a/libetpan/src/data-types/mailstream_helper.c +++ b/libetpan/src/data-types/mailstream_helper.c | |||
@@ -77,50 +77,57 @@ char * mailstream_read_line_append(mailstream * stream, MMAPString * line) | |||
77 | if (stream == NULL) | 77 | if (stream == NULL) |
78 | return NULL; | 78 | return NULL; |
79 | 79 | ||
80 | do { | 80 | do { |
81 | if (stream->read_buffer_len > 0) { | 81 | if (stream->read_buffer_len > 0) { |
82 | size_t i; | 82 | size_t i; |
83 | 83 | ||
84 | i = 0; | 84 | i = 0; |
85 | while (i < stream->read_buffer_len) { | 85 | while (i < stream->read_buffer_len) { |
86 | if (stream->read_buffer[i] == '\n') | 86 | if (stream->read_buffer[i] == '\n') |
87 | return mailstream_read_len_append(stream, line, i + 1); | 87 | return mailstream_read_len_append(stream, line, i + 1); |
88 | i++; | 88 | i++; |
89 | } | 89 | } |
90 | if (mailstream_read_len_append(stream, line, | 90 | if (mailstream_read_len_append(stream, line, |
91 | stream->read_buffer_len) == NULL) | 91 | stream->read_buffer_len) == NULL) |
92 | return NULL; | 92 | return NULL; |
93 | } | 93 | } |
94 | else { | 94 | else { |
95 | ssize_t r; | 95 | ssize_t r; |
96 | 96 | ||
97 | r = mailstream_feed_read_buffer(stream); | 97 | r = mailstream_feed_read_buffer(stream); |
98 | if (r == -1) | 98 | if (r == -1) |
99 | return NULL; | 99 | return NULL; |
100 | 100 | ||
101 | if (r == 0) | 101 | if (r == 0) { |
102 | break; | 102 | // LR |
103 | // this avoids a memory access violation later when trying | ||
104 | // to remove_trailing_eol from a null string | ||
105 | if ( line->len == 0 ) | ||
106 | return NULL; | ||
107 | else | ||
108 | break; | ||
109 | } | ||
103 | } | 110 | } |
104 | } | 111 | } |
105 | while (1); | 112 | while (1); |
106 | 113 | ||
107 | return line->str; | 114 | return line->str; |
108 | } | 115 | } |
109 | 116 | ||
110 | char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line) | 117 | char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line) |
111 | { | 118 | { |
112 | if (!mailstream_read_line(stream, line)) | 119 | if (!mailstream_read_line(stream, line)) |
113 | return NULL; | 120 | return NULL; |
114 | 121 | ||
115 | remove_trailing_eol(line); | 122 | remove_trailing_eol(line); |
116 | 123 | ||
117 | return line->str; | 124 | return line->str; |
118 | } | 125 | } |
119 | 126 | ||
120 | int mailstream_is_end_multiline(const char * line) | 127 | int mailstream_is_end_multiline(const char * line) |
121 | { | 128 | { |
122 | if (line[0] != '.') | 129 | if (line[0] != '.') |
123 | return FALSE; | 130 | return FALSE; |
124 | if (line[1] != 0) | 131 | if (line[1] != 0) |
125 | return FALSE; | 132 | return FALSE; |
126 | return TRUE; | 133 | return TRUE; |