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 @@ -53,98 +53,105 @@ static void remove_trailing_eol(MMAPString * mmapstr) char * mailstream_read_line(mailstream * stream, MMAPString * line) { if (mmap_string_assign(line, "") == NULL) return NULL; return mailstream_read_line_append(stream, line); } static char * mailstream_read_len_append(mailstream * stream, MMAPString * line, size_t i) { size_t cur_size; cur_size = line->len; if (mmap_string_set_size(line, line->len + i) == NULL) return NULL; if (mailstream_read(stream, line->str + cur_size, i) < 0) return NULL; return line->str; } char * mailstream_read_line_append(mailstream * stream, MMAPString * line) { if (stream == NULL) return NULL; do { if (stream->read_buffer_len > 0) { size_t i; i = 0; while (i < stream->read_buffer_len) { if (stream->read_buffer[i] == '\n') return mailstream_read_len_append(stream, line, i + 1); i++; } if (mailstream_read_len_append(stream, line, stream->read_buffer_len) == NULL) return NULL; } else { ssize_t r; r = mailstream_feed_read_buffer(stream); if (r == -1) return NULL; - if (r == 0) - break; + if (r == 0) { + // LR + // this avoids a memory access violation later when trying + // to remove_trailing_eol from a null string + if ( line->len == 0 ) + return NULL; + else + break; + } } } while (1); return line->str; } char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line) { if (!mailstream_read_line(stream, line)) return NULL; remove_trailing_eol(line); return line->str; } int mailstream_is_end_multiline(const char * line) { if (line[0] != '.') return FALSE; if (line[1] != 0) return FALSE; return TRUE; } #if 1 char * mailstream_read_multiline(mailstream * s, size_t size, MMAPString * stream_buffer, MMAPString * multiline_buffer, size_t progr_rate, progress_function * progr_fun) { size_t count; char * line; size_t last; if (mmap_string_assign(multiline_buffer, "") == NULL) return NULL; count = 0; last = 0; while ((line = mailstream_read_line_remove_eol(s, stream_buffer)) != NULL) { if (mailstream_is_end_multiline(line)) return multiline_buffer->str; if (line[0] == '.') { |