-rw-r--r-- | kmicromail/libetpan/tools/mailstream_helper.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/kmicromail/libetpan/tools/mailstream_helper.c b/kmicromail/libetpan/tools/mailstream_helper.c index 146f955..92f4ffe 100644 --- a/kmicromail/libetpan/tools/mailstream_helper.c +++ b/kmicromail/libetpan/tools/mailstream_helper.c @@ -77,50 +77,57 @@ 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; |